DIY: Queue Reconstruction by Height

Solve the interview question "Queue Reconstruction by Height" in this lesson.

Problem statement

In this problem, you are given an array of people, which has the attributes of a few people in a queue. Here, each people[i] = [hi, ki], where the ith array contains hi as the height of the ith person and ki people standing in front of the ith person, in the queue, who have a height greater than or equal to hi.

Your task is to reconstruct and return the people queue, which is represented by the input array called people. Each person, i, must have exactly ki people in front of them with a height hi that is greater than their height. The output queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attribute of the jth person in the queue.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.