Skip to content
RED SAGSkills

Balance Point of a Beam

Weights are placed along a beam, weights[i] at position i. Position i is a *balance point* when the total weight strictly to its left equals the total weight strictly to its right (an empty side weighs 0).

Return the leftmost balance point, or -1 if there is none.

Example 1

Input: weights = [1, 7, 3, 6, 5, 6]
Output: 3
Explanation: Left of index 3: 1 + 7 + 3 = 11. Right: 5 + 6 = 11.

Example 2

Input: weights = [1, 2, 3]
Output: -1

Constraints

  • 1 <= weights.length <= 10^5
  • -1000 <= weights[i] <= 1000
Hint 1

Compute the total once.

Hint 2

While scanning, the right side equals total - left - weights[i].

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer, Game Developer

Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.