You are viewing a single comment's thread. Return to all comments →
static int[] icecreamParlor(int m, int[] arr) { int[] index = new int[2]; Map<Integer,Integer> map = new HashMap<>(); for(int i = 0; i < arr.length; i++) { if(map.containsKey(m - arr[i])) { index[0] = map.get(m - arr[i]); index[1] = i + 1; return index; } map.put(arr[i], i + 1); } return index; }
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 →
Java Solution in O(n)