You are viewing a single comment's thread. Return to all comments →
Short JAVA solution, using priority-queue to optimize sorted insertions
public static int cookies(int k, List<Integer> cookies) { int result = 0; PriorityQueue<Integer> cookiesSorted = new PriorityQueue<>(cookies); while (cookiesSorted.size() >= 2 && cookiesSorted.peek() < k) { cookiesSorted.add(cookiesSorted.poll() + 2 * cookiesSorted.poll()); result++; } return cookiesSorted.peek() < k ? -1 : result; }
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 →
Short JAVA solution, using priority-queue to optimize sorted insertions