MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / sortPeople

Method sortPeople

SortThePeople.java:2–25  ·  view source on GitHub ↗
(String[] names, int[] heights)

Source from the content-addressed store, hash-verified

1class 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}

Callers

nothing calls this directly

Calls 1

sortMethod · 0.80

Tested by

no test coverage detected