Reported September 2026
Amazongreedy

Inventory Allocation

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Amazon Inventory Allocation question, reported in September 2026, is simulating the round-robin one item at a time. With inventory up to 10^9, that loop never finishes. This is a sorting plus greedy problem dressed up as a simulation. Group requests by bid, process the highest bid first, and decide who gets at least one item without ever handing out items individually. If you're staring at the invite and the clock is running, learn the group-level shortcut below. StealthCoder sits invisibly as a safety net on the live OA if your mind goes blank.

The problem

You are given a list of inventory requests. Each request is represented as [customerId, quantity, bidAmount, timestamp].
Allocate totalInventory items using these rules:
Requests with a higher bidAmount are processed before lower bids.
For requests with the same bidAmount, items are distributed in round-robin order by increasing timestamp.
During each round, a customer can receive at most one item.
A customer leaves the current round-robin group once their requested quantity is fulfilled.
Lower bids are considered only after every higher bid has either been fulfilled or inventory is exhausted.
Return the customer IDs of customers who receive no items, in the same order their requests appear in the input.

Function
getUnfulfilledCustomers(requests: int[][], totalInventory: int) → int[]
Complete the function getUnfulfilledCustomers.
int requests[n][4]: rows of [customerId, quantity, bidAmount, timestamp]
int totalInventory: the number of items available
Returns int[]: customers who receive no items.

Examples
Example 1
requests = [[1,5,5,0],[2,7,8,1],[3,7,5,1],[4,10,3,3]]
totalInventory = 18
return = [4]
Customer 2 is fully served first because bid 8 is highest. Customers 1 and 3 then share the remaining inventory at bid 5. No inventory remains for customer 4.
Example 2
requests = [[1,2,10,0],[2,3,10,1],[3,1,5,0]]
totalInventory = 3
return = [3]
The bid-10 group receives all 3 available items before the lower bid is considered, so customer 3 receives none.

Constraints
1 <= requests.length <= 10^5
requests[i].length = 4
customer IDs are unique.
0 <= timestamp <= 10^9
0 <= totalInventory <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: you only need to know who gets zero items. Sort by bid descending and group by bid. For a group of size k with remaining inventory R, if R >= k, everyone in the group gets at least one item, so nobody in that group is unfulfilled. Then you need the real consumption, which is min(R, sum of quantities in the group), since round-robin ends up serving everyone fully or exhausting inventory. If R < k, only the first R customers by timestamp get one item each, and the rest are unfulfilled. Inventory then hits zero, so every lower group is unfulfilled. The pitfall is looping per item, or forgetting to output in original input order. Store the unfulfilled set, then walk the input once to build the answer. Complexity is O(n log n). StealthCoder is the hedge on the live OA if the group logic slips under pressure.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Inventory Allocation cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Inventory Allocation FAQ

What's the trick in Amazon's Inventory Allocation problem?+

Don't simulate item by item. Group requests by bid, highest first. For each group, if remaining inventory covers the group size, everyone gets at least one item. Otherwise only the earliest timestamps get one, and everything below is unfulfilled. You only need group-level math.

How do I handle ties in bid amount?+

Sort each same-bid group by timestamp ascending. Round-robin means earlier timestamps get served first within a round. If inventory runs short mid-round, the earliest timestamps in that group get the last items and later ones get nothing.

Why does the order of the returned customer IDs matter?+

The problem says to return unfulfilled customers in the order their requests appear in the input, not sorted order or processing order. Collect unfulfilled IDs in a set, then iterate the original array once and keep the ones in the set.

How hard is this one really?+

Medium. The logic is short, but the constraints punish naive simulation. With n up to 10^5 and inventory up to 10^9, you need O(n log n). The difficulty is spotting that you only care about who gets zero, not the full distribution.

How do I prepare in 48 hours?+

Write this solution once from scratch. Practice sorting by a composite key, grouping adjacent equal values, and tracking remaining inventory. Test edge cases: inventory 0, one huge group, and a group larger than inventory. Then do two similar greedy allocation problems.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it