Trains the technique from
LeetCode 724Find Pivot IndexThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A steel beam rests on a row of posts. The array loads gives the signed load measured at each post, listed in order along the beam. A negative reading means that post is being pulled upward rather than pressed down.
A post counts as a balance station when the readings on every post listed before it total exactly what the readings on every post listed after it total. The reading on the balance station itself belongs to neither side and is skipped. A post at either end of the row is still eligible, since a side with no posts on it totals zero.
Return the index of the earliest balance station on the beam. When several posts balance the beam, the smallest such index is the answer. When no post balances it, return -1.
Example 1
Before index 2 the readings 5 and -2 total 3, and after it the readings 4 and -1 also total 3. The load of 9 on the station itself is skipped.
Example 2
No post splits the rest of the beam into two equally loaded sides, so the answer is -1.
Example 3
Every post balances the beam here, so the earliest index wins.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def balance_station(loads: list[int]) -> int:public int balanceStation(int[] loads)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.