Product of Array Except Self
Given an array nums, return an array where each element is the product of all elements except itself. Do not use division.
Output space-separated.
Example
1,2,3,4
24 12 8 6
- Input:
numsis a list of integers, here1,2,3,4. Each output position gets , the product of every entry except . - Position 0 drops the : .
- Position 1 drops the : .
- Position 2 drops the : .
- Position 3 drops the : .
- Output: a list the same length as the input, printed space-separated as
24 12 8 6. - Notice why division is banned: with a zero in the input, as in , every position except the zero's own includes that and becomes . Only the zero's position survives, at , giving
0 0 9 0 0. Dividing a total product by can't recover that .
Constraints
- 2 <= len(nums) <= 10^5
- -30 <= nums[i] <= 30
- The product of any prefix or suffix fits in a 32-bit integer