FastPrepRebuild the Queue From Taller-in-Front Counts
Problems/Rebuild the Queue From Taller-in-Front Counts

Rebuild the Queue From Taller-in-Front Counts

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem rebuilds a queue from each person's height and how many taller people stand ahead of them, and returns the heights in queue order. An Adobe CS-1 report pastes this Code360 task, with one example, as one of two coding questions in its first round. The pasted task promises that every height is different and that the counts fit some queue, and it prints the heights. The report notes that a quadratic-time answer built on a sort appeared acceptable to the interviewer on speed.

Our choices: heights from 1 to 10^9, at most 3000 people, the heights returned rather than printed, and new examples (the pasted example is not reused).

The judged task matches the report at about 95%.

Some people stand in a queue, but you only know, for each person i, their height heights[i] and infront[i]: how many people taller than them stand somewhere in front of them.

Rebuild the queue. Return the heights in queue order, from the front to the back. Because all heights are different, the queue is unique.

Function

orderQueue(heights: int[], infront: int[]) → int[]

Examples

Example 1

heights = [7,2,9,4]infront = [1,2,0,1]return = [9,4,2,7]

The tallest, 9, has nobody taller in front, so placing people from tallest to shortest: 9 goes first; 7 needs 1 taller person in front, so it goes after 9; 4 needs 1, so it goes right after 9 (before 7); 2 needs 2, so it goes after 9 and 4. The queue is [9, 4, 2, 7].

Example 2

heights = [10,20,30]infront = [0,0,0]return = [10,20,30]

Nobody has anyone taller in front, so heights must rise from front to back: [10, 20, 30].

Example 3

heights = [8]infront = [0]return = [8]

One person.

Constraints

  • 1 <= heights.length <= 3000 and infront.length == heights.length
  • 1 <= heights[i] <= 10^9, and all heights are different
  • 0 <= infront[i] < heights.length
  • The counts always describe at least one valid queue.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[] orderQueue(int[] heights, int[] infront) {
    // Write your code here.
}
Checking account…