Link: https://leetcode.com/problems/product-of-array-except-self/
Solution:
Topics: prefix sums
Intuition
Not a very difficult problem…basically we borrow the idea from prefix and suffix sums, but instead of sums we make it the running product at every i
. Then to get the product of the array except self, we can perform prefix[i-1]*postfix[i+1]
. Thats all there is to it because multiplication is commutative.
Implementation
Review 1
Easy problem. Be mindful of edge cases.