medium

Product of Array Except Self

Given an integer array, return an array where position i holds the product of all elements except nums[i]. Division is not allowed and the solution must run in linear time.

Constraints
  • 2 ≤ n ≤ 10^5
  • -30 ≤ nums[i] ≤ 30
  • The products fit in a 32-bit integer
  • No division
Examples
in: nums = [1,2,3,4]
out: [24,12,8,6]
in: nums = [-1,1,0,-3,3]
out: [0,0,9,0,0]

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.