Product of Array Except Self
- Array
- Prefix Product
- Suffix Product
Given an integer array nums, return an array answer where answer[i] equals the product of every value in nums except nums[i].
Do not use division. Every prefix and suffix product fits in a signed 32-bit integer.
Four prime factors
- Input
"nums": [2, 3, 5, 7]
- Output
[105, 70, 42, 30]
Explanation: Each output multiplies the other three prime values.
One zero with mixed signs
- Input
"nums": [-2, 4, 0, 5]
- Output
[0, 0, -40, 0]
Explanation: Only the zero position receives the product of all non-zero entries.
Constraints
- 2 <= nums.length <= 100,000
- -30 <= nums[i] <= 30
Follow-up
Can you solve the problem in O(n) time using O(1) auxiliary space, excluding the returned array?