You are given an array people where people[i] = [h, k] represents a person with height h and k people in front of them who have a height greater than or equal to h. Reconstruct and return the queue that satisfies all people. Pattern focus: Sorting First. Sort by height descending and k ascending, then insert each person at index k to preserve the required prefix condition.
people = list of [height, k] pairs
reconstructed queue
Example 1:
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]]
Explanation:
This is the classic example: insert people in descending height order.
Example 2:
Input:
people = [[6,0],[5,0],[4,0],[3,0]]
Output:
[[3,0],[4,0],[5,0],[6,0]]
Explanation:
All k values are 0, so the shortest person ends up first after stable insertion.
Example 3:
Input:
people = [[5,0],[5,1],[5,2]]
Output:
[[5,0],[5,1],[5,2]]
Explanation:
With equal heights, ordering by k gives the unique valid queue.