Queue Reconstruction by Height

# Solution

# Algorithm

  • sort people:
    • in the descending order by height
    • among the guys of the same height, in the ascending order by k-values
  • take guys one by one, and place them in the output array at the indexes equal to their k-values.
  • return output array.
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
    res = []
    people.sort(key = lambda elt: (-elt[0], elt[1]))
    for person in people:
        res.insert(person[1], person)
    return res