← All problems

Product of Array Except Self

Medium arraysprefix-suffix LeetCode ↗
Given nums, return an array where answer[i] is the product of all elements except nums[i]. No division; O(n) time.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1) excluding output

Common pitfalls

  • Using division (fails on zeros)
  • Extra arrays when O(1) space is required

Your solution

Log in to save your code and track progress.