Product of Array Except Self
For each index, return the product of every other element. Do not use division; aim for linear time and constant auxiliary space beyond the answer.
Example 1
nums = [2,3,4][12,8,6]Explanation
Exclude each position: 34=12, 24=8, and 2*3=6.
Example 2
nums = [0,5,0][0,0,0]Explanation
Each product still contains at least one of the two zeroes.
Example 3
nums = [-2,0,3][0,-6,0]Explanation
Only excluding the zero leaves a nonzero product: -2*3=-6.
Constraints
- 2 <= len(nums) <= 100000
- Values are -30..30
- Every prefix, suffix and answer product fits a signed 32-bit integer
Function contract
productExceptSelfArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[2,3,4]