We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static List jimOrders(List> orders) {
// Write your code here
LinkedHashMap map = new LinkedHashMap<>();
int i=0;
while(i<orders.size()){
int sum = orders.get(i).get(0) + orders.get(i).get(1);
map.put(i+1, sum);
i++;
}
List<Map.Entry<Integer,Integer>> list = new ArrayList<>(map.entrySet());
Collections.sort(list,new Comparator<Map.Entry<Integer,Integer>>() {
public int compare(Map.Entry<Integer,Integer> o1,
Map.Entry<Integer,Integer> o2){
return o1.getValue()-o2.getValue();
}
});
List<Integer> ans = new ArrayList<>();
i=0;
for(Map.Entry<Integer,Integer> m : list){
//System.out.println(m.getKey() +" "+m.getValue());
ans.add(m.getKey());
}
return ans;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jim and the Orders
You are viewing a single comment's thread. Return to all comments →
java
public static List jimOrders(List> orders) { // Write your code here LinkedHashMap map = new LinkedHashMap<>();