Trains the technique from
LeetCode 1834Single-Threaded CPUThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A machine shop owns one lathe, and tasks.length jobs are booked on it. Job i is described by tasks[i] = [arrival_i, runtime_i]: the work order lands on the bench at minute arrival_i, and once the lathe starts it the job occupies the lathe for runtime_i minutes without a break.
The lathe never runs two jobs at once and is never stopped part way through a job. It follows one rule whenever it becomes free, and also at the very start:
runtime_i. If several share the smallest runtime, it starts the one with the lowest job number.A work order that lands at exactly the minute the lathe becomes free counts as having landed and may be started right then.
Return the job numbers in the order the lathe starts them.
Example 1
At minute 1 only job 0's order has landed, so the lathe takes it and is busy until minute 5. By then both remaining orders have landed, and job 2 needs one minute against job 1's two, so job 2 goes on next and job 1 last.
Example 2
Job 0 runs from minute 1 to minute 3. Nothing else has landed, so the lathe stands idle until job 1's order arrives at minute 10.
Example 3
All three orders land at minute 1. Job 1 needs one minute, job 2 needs two, job 0 needs three, and the lathe works through them in that order.
Example 4
The three orders land together and all ask for five minutes, so the lowest job number wins each time.
Example 5
Job 0 runs from minute 1 to minute 4. Job 1's order lands exactly at minute 4, so it is in the running alongside job 2 and its single minute is the shorter of the two.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def get_order(tasks: list[list[int]]) -> list[int]:public int[] getOrder(int[][] tasks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.