← Prefix Sum

Pattern Recognition Drill

#133 — Product of Array Except Self

Medium Arrays & Strings

The Problem

Given array nums, return an array where each element is the product of all other elements. No division allowed.

What approach would you use?

Think about it before scrolling down.

Key Signals

Prefix Sum

Build left product array, then multiply in right products in reverse. O(n) time, O(1) extra space.

Alt: Two Pointers

Left pointer accumulates prefix, right pointer accumulates suffix simultaneously.

Common Trap

Don't use division (fails on zeros). The prefix/suffix approach handles zeros naturally.

← #132