Pattern Recognition Drill
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.
Build left product array, then multiply in right products in reverse. O(n) time, O(1) extra space.
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.