Problem
You get an integer array nums. For each index, the left sum is the sum of the items on its left. The right sum is the sum of the items on its right. A pivot index is an index where the left sum is equal to the right sum.
For index 0, the left sum is 0, because no items are on its left. For the last index, the right sum is 0 for the same reason.
Return the leftmost pivot index. If no pivot index exists, return -1.
Example 1
- Input:
- nums = [2,5,1,3,4]
- Output:
- 2
- Explanation:
- The items on the left of index 2 have the sum
2 + 5 = 7. The items on its right have the sum3 + 4 = 7.
Example 2
- Input:
- nums = [1,2,3]
- Output:
- -1
- Explanation:
- No index has equal sums on its left and on its right.
Example 3
- Input:
- nums = [4,-3,3]
- Output:
- 0
- Explanation:
- For index 0, the left sum is 0. The right sum is
-3 + 3 = 0.
Constraints
- 1 <= nums.length <= 10^4
- -1000 <= nums[i] <= 1000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Find Indices With Index and Value Difference I
Coding
- Find Indices With Index and Value Difference II
Coding
- Find the Index of Permutation
Coding
- Find the Index of the First Occurrence in a String
Coding · Boyer–Moore String-Search Algorithm · Knuth–Morris–Pratt Algorithm · String
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Google
Leetcode 724. Find Pivot Index
Reported Dec 11, 2024 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source