 All Problems
Find Pivot Index
easy
arrays
prefix sum
amazon
facebook

Given an array of integers nums, calculate the pivot index. The pivot index is where the sum of all numbers to the left equals the sum to the right. Return the leftmost pivot index or -1 if none exists.

Example 1:

Input: 1 7 3 6 5 6
Output: 3

Example 2:

Input: 1 2 3
Output: -1

Input format: Space-separated integers.

Output format: Pivot index or -1.

Run to check your code against the sample cases, or submit to run every case