• + 1 comment
    # using heap sort
    import heapq
    def cookies(k, nums):
        # Write your code here
        heapq.heapify(nums)
        count =0
        
        while(nums):
            x = heapq.heappop(nums)
            if x>=k:
                return count
            
            if not nums:
                return -1
            y = heapq.heappop(nums)
            
            #formula
            n = x + (2*y)
            heapq.heappush(nums, n)
            count+=1
            
        # loop exits without giving count
        return -1