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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

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
Hash Map
Counting
Multisets
Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported