Queue Reconstruction by Height
You are given an array people where people[i] = [h_i, k_i] means the i-th person has height h_i and exactly k_i people in front of them who are at least as tall. Reconstruct and return the queue (as a list of [h, k] pairs) that satisfies every person's k count.
Open official problem prompt ↗Rebuild the original line so that each person has exactly the stated number of equal-or-taller people standing ahead of them.
Like seating guests tallest-first: since anyone already seated can be seen over the newcomers, a new person's 'count ahead' is just the seat number you slide them into.
- Input
- people = [[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]]
- Why
- Every person ends up with exactly k taller-or-equal people ahead of them, e.g. [4,4] has four people of height >= 4 in front.
1 <= people.length <= 20000 <= h_i <= 10^60 <= k_i < people.length