records, one per person, in no particular order: records[i] = [h, k] means the person is h tall and had exactly k people at least h tall standing ahead of them.
Rebuild the line: return the same records ordered from the front of the line to the back. A valid line is guaranteed to exist, and it is unique.records=[[3, 0], [6, 0], [3, 1], [5, 1]] → [[3, 0], [3, 1], [6, 0], [5, 1]]
In the line [[3, 0], [3, 1], [6, 0], [5, 1]], the second person of height 3 has one person at least as tall ahead (the first one, also 3), and the person of height 5 has only the person of height 6 ahead who is at least as tall.
records=[[4, 2], [4, 0], [4, 1]] → [[4, 0], [4, 1], [4, 2]]
Everyone is the same height, and equal heights count, so they line up by the second number.
records=[[7, 0]] → [[7, 0]]
One person makes a line of one.
records.length ≤ 2000h ≤ 10⁶k < records.lengthrecords=[[3, 0], [6, 0], [3, 1], [5, 1]]
[[3, 0], [3, 1], [6, 0], [5, 1]]
Run checks the first 3 tests in your browser. Submit checks all 67 tests on the server, hidden ones included.