Product Except Self
HardAcc. 84.4%
+45 XP 20
The Cumulative Multiplier
Imagine you need to calculate the influence of every element in a system except for itself. The most efficient way to do this without division is to pre-calculate the "influence from the left" and the "influence from the right."
The Assignment
Your mission is to calculate the product excluding the self. Your function receives nums.
- Create a prefix array where each index
istores the product of all elements to its left. - Create a suffix array where each index
istores the product of all elements to its right. - For each index, multiply the prefix and suffix values.
- Print the resulting products on separate lines.
01EXAMPLE 1
Input
[1, 2, 3, 4]Output
24
12
8
6Explanation: 1: 234=24. 2: 134=12, etc.
Constraints
- Do not use the division operator (`/`).
- O(n) time complexity.
ArraysPrefix Sum
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
nums[1,2,3,4]
Expected Output
24 12 8 6
Click RUN to test your solution