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.
importheapqclassMinHeap:def__init__(self,A):self.harr=A[:]heapq.heapify(self.harr)defextractMin(self):returnheapq.heappop(self.harr)defgetMin(self):returnself.harr[0]defgetSize(self):returnlen(self.harr)definsertKey(self,k):heapq.heappush(self.harr,k)defcookies(k,A):# Write your code hereh=MinHeap(A)res=0whileh.getMin()<k:ifh.getSize()==1:return-1first=h.extractMin()second=h.extractMin()h.insertKey(first+(second*2))res+=1returnres
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 →
PYTHON3 SOLUTION: