Ice Cream Parlor

  • + 0 comments
    public static List<Integer> icecreamParlor(int m, List<Integer> arr) {
    // Write your code here
        Map<Integer, Integer> costVsIndex = new HashMap<>();
        List<Integer> result = new ArrayList<>();
        for(int i = 0; i< arr.size(); i++) {
            Integer remaining = m - arr.get(i);
            if(costVsIndex.containsKey(remaining)) {
                 result.add(costVsIndex.get(remaining) + 1);
                 result.add(i + 1);
            } else {
                costVsIndex.put(arr.get(i), i);
            }
        }
        return result;
    }
    

    }