Link:
Track: Amazon Tag

Question

Restate

Edge Case


Method 1 - heap TLE
Method 2 - greedy

Method 1 - heap

Approach

(discussed at lease two approach?)

Complexity

  • Time Complexity: O()
  • Space Complexity:

Code

import heapq
class Solution:
    def maxProfit(self, inventory: List[int], orders: int) -> int:
        heap = []
        for ball in inventory:
            heapq.heappush(heap, -ball)
        
        total = 0
        while orders:
            val = -heapq.heappop(heap)
            if val == 0:
                break
            total += val
            heapq.heappush(heap, -(val - 1))
            orders -= 1
        
        return total

History

  • Feb-18-2026 Peeked