You are viewing a single comment's thread. Return to all comments →
Simple Python solution using a Heap:
n = len(A) iterations=0 i=0 heapq.heapify(A) while i < n: minA = heapq.heappop(A) if minA < k: if len(A)<1: return -1 minB = heapq.heappop(A) newValue= (1 * minA) + (2 * minB) heapq.heappush(A,newValue) i+=1 iterations+=1 else: break return iterations
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 →
Simple Python solution using a Heap: