Jesse and Cookies

  • + 0 comments
    from heapq import heappush, heappop, heapify
    
    def cookies(k, A):
        heapify(A)
        i = 0
        while A[0] < k and len(A) > 1:
            heappush(A, heappop(A) + (heappop(A) * 2))
            i += 1
        return i if A[0] >= k else -1