Allocate inventory to customer bids by bid amount, using round-robin on ties.
You are managing an inventory system at Amazon. You receive N bids from customers in the format [customerId, bidAmount, quantity, bidPlacedAt].
Allocate inventory to customers with these rules:
- Customers with a higher bid amount get priority.
- If multiple customers have the same bid amount, allocate inventory round-robin among them (1 item per customer per cycle) until inventory runs out or their bid is fully satisfied.
Return the list of customer IDs whose bids are not fully fulfilled.
Example 1: bids = [[1,3,1,1],[2,4,2,2]], totalInventory = 1 output: [1] Customer 2 has the higher bid amount, so gets priority and takes the only unit; customer 1's bid goes unfulfilled.
Example 2: bids = [[1,3,2,1],[2,3,2,2],[3,3,1,3]], totalInventory = 4 output: [] All customers bid the same amount, so inventory is allocated round-robin: cycle 1 gives 1 unit each to customers 1, 2 and 3 (3 units used, 1 remaining). Cycle 2 gives the last unit to customer 1, who still needs more and is next in order. Final allocation: customer 1 gets 2, customer 2 gets 2, customer 3 gets 1.
Format · 40-minute OA coding question.
Community answers
Related courses


