Here is the solution:
function reconstructQueue(people)
sort people by height descending, then k ascending
result := []
for each (h, k) in people
result.insert(at index k, value (h, k))
return result
Time: due to insertions. Space: .
Example: first, then at index , then at index (shifts right), and so on. Each insertion places the person correctly relative to taller people already present.