DIY: Queue Reconstruction by Height
Solve the interview question "Queue Reconstruction by Height" in this lesson.
We'll cover the following
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 i
th array contains hi
as the height of the i
th person and ki
people standing in front of the i
th 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 j
th person in the queue.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.