31. Pivot Index

Find the pivot index where the sum of elements to the left equals the sum of elements to the right.
Example 1
Input: nums = [2,1,-1,1,2]
Output: 2
Explanation: For this array index 2 is the pivot — sums on both sides are equal.
Example 2
Input: nums = [1,2,3]
Output: -1
Explanation: For no index is the sum on the left equal to the sum on the right — return -1.
Example 3
Input: nums = [1,7,3,6,5,6]
Output: 3
Explanation: Find the index where the sum on the left equals the sum on the right: for this example pivot=3 (index 3).
arraysmedium
JavaScript
Loading...
Line 1, Char 1