Jim and the Orders

  • + 0 comments

    Java8

    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; }