Back to DSA
Product of Array Except Self
mediumConstruct an output array where each position holds the product of every element in the input array except the one at that position. You must accomplish this without using division, and the algorithm should run in linear time. The problem guarantees that all intermediate products fit within standard integer range.
Examples
Example 1:
Input:
nums = [2,3,4,5]Output:
[60,40,30,24]Explanation: Position 0: 3*4*5=60, position 1: 2*4*5=40, position 2: 2*3*5=30, position 3: 2*3*4=24.
Example 2:
Input:
nums = [-2,1,0,4,3]Output:
[0,0,-24,0,0]Explanation: Because one element is zero, every product that does not skip the zero evaluates to 0.
Hints
1234567