Process Priorities After Execution

Asked at Amazon · Coding Questions · Difficulty: Medium

Processes sit in a queue with priorities `priority`. Repeat: find the maximum priority shared by at least two processes (call it `p`); if none exists or `p == 0`, stop. Otherwise take the two lowest-index processes with priority `p`, remove the first, and set the second's priority to `floor(p / 2)`. Return the remaining priorities in their original relative order.

Loading the problem…