Check Whether Shelf Stock Covers Every Item in an Order
Last updated: November 29, 2026
Quick Overview
Given a customer order as a list of item IDs (with repeats meaning quantity) and a shelf's stock as another list of item IDs, return whether the shelf alone can fulfill the order, and if not, return the shortfall per item.
Amazon
November 29, 20260
0
0 solved
Given a customer order as a list of item IDs (with repeats meaning quantity) and a shelf's stock as another list of item IDs, return whether the shelf alone can fulfill the order, and if not, return the shortfall per item.
A quick multiset question in the style of Amazon assessments about picking from a single bin. It checks that you use counting rather than repeated list removal, and that the output is useful to an operator (what is missing, not just false).
What the Interviewer Expects
- Count both lists with a hash map
- Return a clear shortfall structure
- Avoid O(n * m) list.remove loops
- Handle empty order and empty shelf
- Keep output deterministic
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you fulfill from several shelves minimizing the number of shelves visited?
- What if stock is reserved by other in-flight orders?
- How would this run if stock counts live in a remote service?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Order and stock are lists of strings, possibly empty. Return (True, {}) when fulfillable, else (False, shortfall) where shortfall maps item ID to the number of units missing. An empty order is alw...
High-Level Design
Count the stock once with Counter. Then for each distinct item in the order compare required vs available and record required - available when positive. This is a single pass over each list. `Coun...