LC 238
LeetCode 238 · Medium

Product of Array Except Self

Return an array where each element is the product of all the others, without using division.

Math → · High frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the math shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Math — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

Two passes: a left-to-right prefix product, then a right-to-left suffix product folded into the same output array. The prefix and suffix sweeps each contribute one side of the product.

AspectValue
PatternMath
Recognise it byAnswer[i] depends on everything but i; no division allowed.
Time complexityO(n)
Space complexityO(1)
DifficultyMedium

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.