| 1 | class Solution { |
| 2 | public String[] sortPeople(String[] names, int[] heights) { |
| 3 | int n = heights.length; |
| 4 | Integer index[] = new Integer[n]; |
| 5 | //ON |
| 6 | for(Integer i=0;i<n;i++){ |
| 7 | index[i] = i; |
| 8 | } |
| 9 | //NlogN |
| 10 | //merge sort, quick sort .... |
| 11 | Arrays.sort(index, new Comparator<Integer>(){ |
| 12 | public int compare(Integer a, Integer b){ |
| 13 | return heights[b] - heights[a]; |
| 14 | } |
| 15 | }); |
| 16 | String res[] = new String[n]; |
| 17 | int i=0; |
| 18 | // On |
| 19 | for(Integer ind : index){ |
| 20 | res[i] = names[ind]; |
| 21 | i++; |
| 22 | } |
| 23 | return res; |
| 24 | |
| 25 | } |
| 26 | } |