FunctionRacerProblemsRace

Rebuild the Line

MediumSorting and searchingPython, JavaScript, TypeScript, Java, C++

People stood in a line. Each of them wrote a note [height, ahead]: their own height, and how many of the people in front of them were at least as tall.

people holds the notes in a shuffled order. Return the notes in the order of the line, front first. The notes always fit exactly one line.

Example 1

people [[8,1],[2,4],[3,0],[6,1],[8,0]]
returns [[3,0],[8,0],[6,1],[8,1],[2,4]]

From the front the heights are 3, 8, 6, 8, 2. The 6 and the second 8 each have one person at least as tall in front, and the 2 has all four.

Example 2

people [[1,1],[2,0]]
returns [[2,0],[1,1]]

The taller person has nobody in front, so the person of height 1 stands behind and counts one.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems