Example 1
Input
nums = [1, 2, 3, 4]
Output
[24, 12, 8, 6]
Loading CodeSprint...
/problems/product-except-self
Return an array where each position contains the product of every input value except the value at that same position.
Implement this function and return the result. CodeSprint supplies each test case automatically.
productExceptSelf(nums) → number[]Input
nums = [1, 2, 3, 4]
Output
[24, 12, 8, 6]
Input
nums = [-1, 1, 0, -3, 3]
Output
[0, 0, 9, 0, 0]
Constraints
2 <= nums.length <= 100,000 -30 <= nums[i] <= 30 Every result fits in a JavaScript safe integer.