We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def cookies(k,A):
# convert list A to priority queue heapq
heapq.heapify(A)
iteration = 0
while any(c < k for c in A) and len(A) > 1:
mix = heapq.heappop(A) + 2 * heapq.heappop(A)
heapq.heappush(A,mix)
iteration += 1
if not all(c >= k for c in A):
return -1
return iteration
Cookie support is required to access HackerRank
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 →
def cookies(k,A): # convert list A to priority queue heapq heapq.heapify(A)