Unfulfilled Customers by Inventory Priority
Learn this problemProblem statement
Allocate limited inventory items based on a priority algorithm.
During a flash sale on Amazon, customers submit requests for a limited quantity of a product. Each request includes [customerId, quantity, bidAmount, timestamp].
Items are allocated using these rules:
- Higher bids get priority.
- If multiple customers have the same bid, allocate items in a round-robin manner based on the earliest timestamp until all inventory is allocated.
- A customer gets one item per round until their request is fulfilled.
Return the IDs of customers who received no items.
Note: Round-robin allocation means cycling through the tied customers in order of their timestamps, granting exactly one item to each customer per cycle, until either the inventory runs out or all their requested quantities are fulfilled.
Function
getUnfulfilledCustomers(requests: int[][], totalInventory: int) → int[]Complete the function getUnfulfilledCustomers with the following parameters:
int requests[requests[0]...requests[n-1]]: 2D array of integers where each row is[customerId, quantity, bidAmount, timestamp]int totalInventory: an integer, the total number of items available for allocation
Returns
int[]: a list of customer IDs who did not receive any items, sorted in ascending order
Source update (June 28, 2026): I cleaned up this prompt using the source images available for this problem, including an additional Amazon New Grad source from May 12, 2026. If you have a clearer original source or notice something wrong, please let us know and we'll fix it. If a better source shows up later, I'll update this again. 🦦
Examples
Example 1
requests = [[1, 5, 5, 0], [2, 7, 8, 1], [3, 7, 5, 1], [4, 10, 3, 3]]totalInventory = 18return = [4]The first three requests have a higher bidding amount than the 4th request, and the total quantity requested in the first three requests is 19, whereas the available inventory is 18, so only one left without any allocation will be customer ID 4.
Constraints
1 ≤ n < 10^41 ≤ customerId, quantity, bidAmount, timestamp, totalInventory < 10^8
More Amazon problems
- HTTP Request RedirectionOA · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026