You are viewing a single comment's thread. Return to all comments →
public static List<Integer> jimOrders(List<List<Integer>> orders) { // Write your code here List<Integer> list=new ArrayList<>(); Map<Integer,Integer> map=new HashMap<>(); int x; for(int i=0;i<orders.size();i++){ x=orders.get(i).get(0)+orders.get(i).get(1); map.put(i+1, x); } //map is sorted by values final Map<Integer, Integer> sortedByTime = map.entrySet() .stream() .sorted(Map.Entry.comparingByValue()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); for(int i : sortedByTime.keySet()){ list.add(i); }
return list; }
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 →
Java8
return list; }