weights lists loads laid out in a row at positions 0, 1, 2, ... If you put a support under position i, load i itself goes to neither side, and the sum on the left must equal the sum on the right. An empty side weighs 0. Loads may be negative.
Return the leftmost position where the row balances, or -1 if there is none.weights=[3, 4, 9, 1, 6] → 2
Left of index 2 sits 3 + 4 = 7, right of it 1 + 6 = 7. No earlier index works: at index 0 the left side is 0 and the right side is 20.
weights=[-2, 5, -5] → 0
At index 0 the left side is empty (sum 0) and the right side is 5 + (-5) = 0, so it already works.
weights=[1, 2, 3] → -1
weights) ≤ 10⁵weights[i] ≤ 1000weights=[3, 4, 9, 1, 6]
2
Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.