No zeros
Input
nums = [1, 2, 3, 4]
Output
[24, 12, 8, 6]
Product of all is 24. For index 0: 24/1=24, index1:24/2=12, etc. But you must not use division in implementation.
Full lesson preview
Return an array where each element is the product of all other elements in the input array, without using division.
Problem statement
Task
Examples
Input
nums = [1, 2, 3, 4]
Output
[24, 12, 8, 6]
Product of all is 24. For index 0: 24/1=24, index1:24/2=12, etc. But you must not use division in implementation.
Input format
Output format
Constraints
Samples
Input
nums = [0, 4, 0]
Output
[0, 0, 0]
Two zeros mean every product-except-self is zero.