PROBLEM 05 OF 75

Product of Array Except Self

Return the product of every value except the value at that index, without division.

PATTERNArray scans & hashingName what you need to remember before choosing the container.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Return the product of every value except the value at that index, without division.

WHY THIS FITS

Each answer is left product × right product.

COMPLEXITY

O(n) time · O(1) extra space excluding output

COMMON FAILURE

Zeros break division and off-by-one updates include the current value.

THE REASONING, IN ONE PLACE

How to solve Product of Array Except Self

The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.

What the question asks

Return the product of every value except the value at that index, without division.

Why Array scans & hashing fits

Each answer is left product × right product.

State to maintain

The output stores prefix products; one running suffix multiplies them in reverse.

Transition

Sweep left to build prefixes, then right while updating the suffix.

Time and space

O(n) time · O(1) extra space excluding output

Counterexample to the tempting mistake

Zeros break division and off-by-one updates include the current value.

Prove it again tomorrow

Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.

Open blank recall ↗