FDEInterviews logoFDE/Interviews
Coding & DSA / 78
mediumMetaAmazon

Product of array except self, without using division

Build the output from prefix products on a left-to-right pass, then fold in suffix products on a right-to-left pass using the output array itself as scratch. O(n) time, O(1) extra space. The interesting part is why division is banned and what it costs when the input has zeros.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

Build the output from prefix products on a left-to-right pass, then fold in suffix products on a right-to-left pass using the output array itself as scratch. O(n) time, O(1) extra space. The interesting part is why division is banned and what it costs when the input has zeros.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

The division solution (product of everything, then divide out each element) is the first thing candidates blurt. It is disqualified for two honest reasons: the prompt forbids it, and it breaks on zeros. One zero makes the total product zero, so dividing is undefined for every position; two zeros make every output zero. Handling that needs a zero-count special case, which is uglier than the prefix/suffix trick. Make the candidate articulate the zero failure, not just recite 'division is not allowed.'

DISCUSSION · 0

No comments yet — be the first to share your approach.