Queue Reconstruction by Height

Medium
Arrays Array Greedy Sorting

People with [height, #people_ahead_taller_or_equal]. Reconstruct queue.

Constraints

1 ≤ n ≤ 2000

Examples

Example 1:
Input: 7 0 4 4 7 1 5 0 6 1 5 2
Output: 5 0 7 0 5 2 6 1 4 4 7 1
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.