FunctionRacerProblemsRace

Find Pivot Index

EasyArraysPython, JavaScript, TypeScript, Java, C++

A pivot index is a position where the sum of the numbers strictly to its left equals the sum of the numbers strictly to its right. An empty side counts as sum 0.

Return the leftmost pivot index of nums, or -1 if there is none.

Example 1

nums [1,7,3,6,5,6]
returns 3

At index 3 the left sum is 1+7+3 = 11 and the right sum is 5+6 = 11.

Example 2

nums [1,2,3]
returns -1

No index balances, so the answer is -1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems