You are viewing a single comment's thread. Return to all comments →
Heap solution with python:
def cookies(k, A): hq.heapify(A) oper = 0 while True : last = hq.heappop(A) if last >=k : return oper if last<k and len(A)<1: return -1 prelast = hq.heappop(A) new_val = last + prelast*2 hq.heappush(A,new_val) oper = oper + 1
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 →
Heap solution with python: