Weights are placed along a beam at positions 0 .. n-1, given as weights. Return the leftmost index i such that the total weight strictly to the left of i equals the total weight strictly to the right of i. Return -1 if no such index exists. An empty side has weight 0.
Examples
Input: weights = [1, 7, 3, 6, 5, 6]
Output: 3
Explanation: 1 + 7 + 3 = 11 and 5 + 6 = 11.
Input: weights = [1, 2, 3]
Output: -1
Input: weights = [2, 1, -1]
Output: 0
Explanation: Nothing is left of index 0 (sum 0) and 1 + (-1) = 0 on the right.
Constraints
0 <= len(weights) <= 10**5-10**4 <= weights[i] <= 10**4- Target: O(n) time, O(1) extra space.
Goals
- Derive the right-hand sum from the total and the left-hand sum
- Avoid recomputing slices inside the loop