You are viewing a single comment's thread. Return to all comments →
Python:
def cookies(k: int, A: list) -> int: heapq.heapify(A) counter = 0 # no. of operations while A[0] < k: # smallest element always first if len(A) < 2: return -1 first = heapq.heappop(A) second = heapq.heappop(A) heapq.heappush(A, first + 2 * second) counter += 1 return counter
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 →
Python: