 All Problems
Queue Reconstruction by Height
medium
array
greedy
sorting
google
facebook

You are given an array of people, people[i] = [hi, ki], where hi is the height of the ith person and ki is the number of people in front of them who have a height greater than or equal to hi.

Reconstruct and return the queue that is represented by the input array. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the 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]]

Constraints:

  • 1 <= people.length <= 2000
  • 0 <= hi <= 10^6
  • 0 <= ki < people.length
Run to check your code against the sample cases, or submit to run every case