Problem · Array

Unfulfilled Customers by Inventory Priority

MediumAmazonNEW GRADOA
See Amazon hiring insights

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 Description

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
01 · Example 1
requests = [[1, 5, 5, 0], [2, 7, 8, 1], [3, 7, 5, 1], [4, 10, 3, 3]]
totalInventory = 18
return = [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^4
  • 1 ≤ customerId, quantity, bidAmount, timestamp, totalInventory < 10^8
More Amazon problems
drafts saved locally
public int[] getUnfulfilledCustomers(int[][] requests, int totalInventory) {
  // write your code here
}
requests[[1, 5, 5, 0], [2, 7, 8, 1], [3, 7, 5, 1], [4, 10, 3, 3]]
totalInventory18
expected[4]
checking account