ASAPUtils Logo ASAPUtils
Week 1

Product of Array Except Self

Product of Array Except Self in two passes with no division, with C++ and JavaScript solutions, a step-by-step visualizer, and why the division shortcut breaks on zeros.

medium Arrays Prefix Sums O(n) time · O(1) space Open on LeetCode ↗

The problem

Given an integer array, return an array where each position holds the product of every element except the one at that position. You must do it without division, in O(n) time.

nums = [1, 2, 3, 4] -> [24, 12, 8, 6]

Related Problems