Insert tallest people first.
When you insert a tall person, shorter people not yet inserted do not affect their value. Sort by height descending, then by ascending. Insert each person at index in the result. Why this works: when you insert person , all people already in the result are at least as tall. Inserting at position means exactly people in front are taller or equal. Shorter people inserted later slot in without disrupting this.