forked from architsingla13/InterviewBit-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderOfPeoplesHeight.java
More file actions
43 lines (32 loc) · 866 Bytes
/
OrderOfPeoplesHeight.java
File metadata and controls
43 lines (32 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Trees;
import java.util.ArrayList;
import java.util.TreeMap;
/**
* Author - archit.s
* Date - 11/11/18
* Time - 12:20 PM
*/
public class OrderOfPeoplesHeight {
public ArrayList<Integer> order(ArrayList<Integer> A, ArrayList<Integer> B) {
ArrayList<Integer> r = new ArrayList<>();
TreeMap<Integer,Integer> map = new TreeMap<>();
for(int i=0;i<A.size();i++){
map.put(A.get(i), B.get(i));
}
while(!map.isEmpty()){
int height = map.lastKey();
int taller = map.get(height);
map.remove(height);
if(r.size() ==0){
r.add(height);
}
else if(taller == 0){
r.add(0,height);
}
else{
r.add(taller,height);
}
}
return r;
}
}