You are viewing a single comment's thread. Return to all 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; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
}