Rebuild the Queue From Taller-in-Front Counts
Problem statement
Some people stand in a queue, but you only know, for each person i, their height heights[i] and infront[i]: how many people taller than them stand somewhere in front of them.
Rebuild the queue. Return the heights in queue order, from the front to the back. Because all heights are different, the queue is unique.
Function
orderQueue(heights: int[], infront: int[]) → int[]Examples
Example 1
heights = [7,2,9,4]infront = [1,2,0,1]return = [9,4,2,7]The tallest, 9, has nobody taller in front, so placing people from tallest to shortest: 9 goes first; 7 needs 1 taller person in front, so it goes after 9; 4 needs 1, so it goes right after 9 (before 7); 2 needs 2, so it goes after 9 and 4. The queue is [9, 4, 2, 7].
Example 2
heights = [10,20,30]infront = [0,0,0]return = [10,20,30]Nobody has anyone taller in front, so heights must rise from front to back: [10, 20, 30].
Example 3
heights = [8]infront = [0]return = [8]One person.
Constraints
1 <= heights.length <= 3000andinfront.length == heights.length1 <= heights[i] <= 10^9, and all heights are different0 <= infront[i] < heights.length- The counts always describe at least one valid queue.