Problem statement
Return the leftmost index whose values to the left sum to the same total as its values to the right, or -1 when none does.
The worked instance is the pivot index; the page teaches the recipe of naming what each side reports before writing any loop.
Examples
Inputa = [1, 7, 3, 6, 5, 6]
Output3
Both sides of index 3 sum to 11.
Inputa = [2, 1, -1]
Output0
The first cell has an empty left side, and the rest of the array sums to 0.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing