You are viewing a single comment's thread. Return to all comments →
Thanks ! Switching to Java 7 worked for me too.
static int cookies(int k, int[] A) { PriorityQueue<Integer> pq = new PriorityQueue<>(A.length); for (int val : A) { pq.add(val); } int counter = 0; while (pq.size() > 1 && pq.peek() < k) { int smallest = pq.poll(); int second = pq.poll(); pq.add(smallest + 2*second); counter++; } if (pq.size() > 1 || pq.peek() >= k) { return counter; } else { return -1; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
Thanks ! Switching to Java 7 worked for me too.