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: 1
Explanation:
For index i = 1:
nums[0] = 2nums[2] = 2No smaller index satisfies the condition, so the answer is 1.
Example 2:
Input: nums = [2,8,2,2,5]
Output: 2
Explanation:
For index i = 2:
2 + 8 = 102 * 5 = 10No smaller index satisfies the condition, so the answer is 2.
Example 3:
Input: nums = [1]
Output: -1
For indexi = 0:
Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 109Loading editor...
[2,1,2]