Java O(n^2) solution with O(n) extra space

The key point of the problem is the, fact that position of any person in the queue, equals to the sum of numbers of taller and shorter people than the current person and standing before it in the queue. Thus the problem reduces to the problem of finding numbers of taller and shorter people standing before each people.

Sort the array in ascending order of their heights O(nlog(n))

For each element, find its proper position. To do so, use greedy algorithm. First assume that the position is k = people[i][1], where k is the number of taller people than i th person, standing before it in the queue. Then, if you meet in range [0,k] anybody shorter than current person, then increment its position (i.e k++). O(n^2)