Ctrl K

Balance Point Index

Easy
Loads sit in a row on a long plank, and their weights are stored in 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.
Example 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.

Example 2
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.

Example 3
weights=[1, 2, 4] → -1

No index has equal sums on both sides.

Constraints
  • 1 ≤ len(weights) ≤ 10⁵
  • -1000 ≤ weights[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Battery Must Not Run Dry EasyBalance After Each Day EasyTotals of Odd-Length Slices EasyThe Hiker's Highest Point EasyThe Busiest Year Easy
loading Python…
Input
weights=[4, -2, 9, 5, -3]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.