You are viewing a single comment's thread. Return to all comments →
Here is my solution. It uses python heapq library. It is fast
def cookies(k, A): import heapq heapq.heapify(A) count = 0 while not all(i >= k for i in A): # until all cookies are >= k if len(A) == 1: return -1 a, b = heapq.heappop(A), heapq.heappop(A) c = a + 2 * b heapq.heappush(A, c) count += 1 return count
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 →
Here is my solution. It uses python heapq library. It is fast