You’re given an integer array, arr. Return a resultant array so that res[i] is equal to the product of all the elements of arr except arr[i].
Write an algorithm that runs in O(n) time without using the division operation.
Constraints:
- 2≤
arr.length ≤105
- −30≤
arr[i] ≤30
- The product of any prefix or suffix of
arr is guaranteed to fit in a 32-bit integer.
So far, you have probably brainstormed some approaches and have an idea of how to solve this problem. Let’s explore some of these approaches and figure out which one to follow based on ...