A generation ship keeps its crew in numbered cryo-pods along a single corridor. At the moment the ship launches (time 0), pod i is sealed and its occupant is put into stasis for exactly duration[i] milliseconds; the pod's occupant wakes the instant that duration elapses. Given the sleep durations of all n pods, report the pods in the order their occupants wake up. If two or more pods share the exact same duration, the pod with the smaller pod number wakes first (ties break by ascending pod number).
A single line with n integers: the pod numbers in the order their occupants wake, space separated.
Example 1
Input
3 5 1 3
Expected
2 3 1
Explanation
Pod 1 sleeps 5ms, pod 2 sleeps 1ms, pod 3 sleeps 3ms. Ordered by ascending duration: pod 2 (1ms), then pod 3 (3ms), then pod 1 (5ms), giving "2 3 1".
Example 2
Input
4 2 2 1 2
Expected
3 1 2 4
Explanation
Pod 3 has the shortest duration (1ms) and wakes first. Pods 1, 2, and 4 all share duration 2ms, so among them the smaller pod number wakes first: pod 1, then pod 2, then pod 4. Result: "3 1 2 4".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →