Ice Cream Parlor

  • + 0 comments

    Java

    public static List<Integer> icecreamParlor(int m, List<Integer> arr) {
            Map<Integer, Integer> flavorMap = new HashMap<>();
            
            for (int i = 0; i < arr.size(); i++) {
                int currentFlavorCost = arr.get(i);
                int complementCost = m - currentFlavorCost;
                
                if (flavorMap.containsKey(complementCost)) {
                    return Arrays.asList(flavorMap.get(complementCost) + 1, i + 1);
                }
                
                flavorMap.put(currentFlavorCost, i);
            }
            
            return null; 
        }