weights (a weight can be negative, think of a balloon pulling up). Find the index of the load that splits the plank evenly: the total weight strictly to its left equals the total weight strictly to its right.
For a load at an edge, the empty side counts as 0. If several indices work, return the leftmost one; if none does, return -1.weights=[4, -2, 9, 5, -3] → 2
Left of index 2 are 4 and -2 (sum 2), right of it are 5 and -3 (also 2). Indices 0 and 1 do not balance.
weights=[7, 3, -3] → 0
Nothing lies left of index 0, so that sum is 0; to the right, 3 + (-3) = 0. This is the leftmost balance point.
weights=[1, 2, 4] → -1
No index has equal sums on both sides.
weights) ≤ 10⁵weights[i] ≤ 1000weights=[4, -2, 9, 5, -3]
2
Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.