[
array
accumulate
]
BinarySearch 0006 Special Product List
Problem statement
https://binarysearch.com/problems/Special-Product-List/
Solution
Equal to leetcode Leetcode 0238. Product of Array Except Self
Complexity
It is O(n)
both for time and space.
Code
class Solution:
def solve(self, nums):
t1 = [1] + list(accumulate(nums, mul))[:-1]
t2 = list(accumulate(nums[::-1], mul))[::-1][1:] + [1]
return [x*y for x, y in zip(t1, t2)]