Find the Smallest Balanced Index
You are given an integer array nums.
An index i is balanced if the sum of elements strictly to the left of i equals the product of elements strictly to the right of i.
If there are no elements to the left, the sum is considered as 0. Similarly, if there are no elements to the right, the product is considered as 1.
Return an integer denoting the smallest balanced index. If no balanced index exists, return -1.
Example 1
Input
nums = [2,1,2]Output
1At index 1, the left sum is 2 and the right product is 2, and no smaller index satisfies the condition.
Example 2
Input
nums = [2,8,2,2,5]Output
2At index 2, the left sum is 2 + 8 = 10 and the right product is 2 * 5 = 10, and no smaller index satisfies the condition.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9