Skip to content

Practice Find Pivot Index

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#724
LeetCode Problem

Find Pivot Index

Problem Statement

Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array. Return the leftmost pivot index. If no such index exists, return -1. Example 1: Example 2: Example 3: Constraints: Note: This question is the same as 1991: https://leetcode.com/problems/find-the-middle-index-in-array/

Source: Find Pivot Index on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,7,3,6,5,6]
Output
3

# Example 2

Input
nums = [1,2,3]
Output
-1

# Example 3

Input
nums = [2,1,-1]
Output
0

Constraints

1 <= nums.length <= 10^4
-1000 <= nums[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Find Pivot Index.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.