Compute Each Warehouse's Demand Product Excluding Its Own Value
Last updated: November 29, 2026
Quick Overview
Given an array of daily demand multipliers, one per warehouse, return an array where entry i is the product of every multiplier except the one at i, without using division and in O(n) time.
Amazon
November 29, 20260
0
0 solved
Given an array of daily demand multipliers, one per warehouse, return an array where entry i is the product of every multiplier except the one at i, without using division and in O(n) time.
This shows up in Amazon online assessments dressed as a supply-chain forecasting step. The grader checks that you avoid division (zeros break it) and that you can produce prefix and suffix products in O(1) extra space beyond the output.
What the Interviewer Expects
- Explain why division fails when any multiplier is zero
- Build prefix products left to right and suffix products right to left
- Reuse the output array to keep extra space O(1)
- Handle arrays containing one or more zeros correctly
- State time and space complexity clearly
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 does the answer change if there are exactly two zeros?
- What if values are large and you must return results modulo 1e9+7?
- How would you support point updates to one multiplier followed by queries?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a list nums of integers with length at least 2 (may contain zeros and negatives). Output res where res[i] is the product of all nums[j] with j != i. No division, O(n) time, and idea...
High-Level Design
The product excluding index i equals (product of everything left of i) times (product of everything right of i).
- Fill
res[i]with the running product ofnums[0..i-1]in a left-to-right pass. 2...