def reconstructQueue(self, people):
people = sorted(people, key=lambda x: x[1])
people = sorted(people, key=lambda x: x[0])
res = []
for p in people:
res.insert(p[1], p)
return res
6 lines python


@StefanPochmann said in 6 lines python:
Ugly oneliner :)
def reconstructQueue(self, people): return reduce(lambda q, p: q.insert(p[1], p) or q, sorted(people, key=lambda (h, t): (h, t)), [])
Can you explain why this approach works?

@StefanPochmann I understand your implementation, I meant the idea. I am asking you because you're very good at explaining things and concepts :)

