Balance Point
You are given a list of integers nums. An index is a balance point when the numbers strictly to its left add up to the same total as the numbers strictly to its right. The number at the index itself belongs to neither side, and an empty side adds up to 0.
Return the first balance point, or -1 if there is none.
Examples
nums = [1, 7, 3, 6, 5, 6] → 3
nums = [1, 2, 3] → -1
nums = [2, 1, -1] → 0
nums = [5] → 0In the first example, 1 + 7 + 3 = 11 and 5 + 6 = 11, with the 6 at index 3 in between. In the third, nothing is left of index 0, and 1 + (−1) = 0.
Constraints
- Between 1 and 20,000 numbers, each between -1,000 and 1,000.
- Aim for O(n): adding up both sides again at every index costs n².
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.