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.
do you knwo what is the difference between your code and:
for some reason having if A[0] >= k: inside while loop makes case 18 fail
def cookies(k, A):
# Write your code here
heapq.heapify(A)
count = 0
while len(A) >= 2:
if A[0] >= k:
return count
x = heapq.heappop(A)
y = heapq.heappop(A)
heapq.heappush(A, x+(2*y))
count += 1
return -1
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
do you knwo what is the difference between your code and: for some reason having if A[0] >= k: inside while loop makes case 18 fail def cookies(k, A): # Write your code here heapq.heapify(A) count = 0 while len(A) >= 2: if A[0] >= k: return count x = heapq.heappop(A) y = heapq.heappop(A) heapq.heappush(A, x+(2*y)) count += 1 return -1