Product of Array Except Self
Return the product of every value except the value at that index, without division.
Why does this pattern fit?
Restate the exact job
Return the product of every value except the value at that index, without division.
Each answer is left product × right product.
O(n) time · O(1) extra space excluding output
Zeros break division and off-by-one updates include the current value.
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.