Jesse and Cookies

  • + 1 comment
    import heapq
    def cookies(k, A):
        heapq.heapify(A)
        ways =0
        
        while len(A) > 1 and A[0] < k :
            a = heapq.heappop(A) 
            b = heapq.heappop(A) *2
            heapq.heappush(A, (a+b))
            ways +=1
    
    				
            
        if A[0] < k:
            return -1
        return ways