Skip to content
Decoder

Queue Reconstruction by Height

Medium

Problem

People stood in a queue, but the list got shuffled. Each entry people[i] = [h, k] says the person has height h and that exactly k people in front of them are at least as tall as they are. Rebuild the queue and return it, front first.

Example 1

people = [[7, 0], [4, 4], [7, 1], [5, 0], [6, 1], [5, 2]]

Example 2

→ [[5, 0], [7, 0], [5, 2], [6, 1], [4, 4], [7, 1]]

Constraints

  • 1 <= people.length <= 2000
  • 0 <= h <= 10^6
  • 0 <= k < people.length
  • The input always describes a valid queue.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.