Find Pivot Index
Use total sum and running left sum to find where left equals right.
Problem Statement
Given an array nums, find the pivot index: the index where the sum of all numbers to the left equals the sum to the right. If no such index exists, return -1. If there are multiple, return the leftmost.
Examples
Example 1
Explanation: Left sum = 1+7+3=11. Right sum = 5+6=11.
Example 2
Explanation: No pivot exists.
Constraints
- 1 ≤ nums.length ≤ 10⁴
- -1000 ≤ nums[i] ≤ 1000
Solutions
For each index, compute left sum and right sum separately. O(n²) due to repeated summations.
Related Concepts
Deepen your understanding with these related topics from our AI Glossary:
Want to master the core concepts?
Our free AI Glossary covers 190+ topics — from Prefix Sum to Dynamic Programming, Machine Learning, SQL, and more. Structured learning tracks for every level.
Stuck? Ask AI to explain it step by step.
Ask Claude, GPT-4o, or Gemini to debug your code, generate test cases, or walk through the intuition. 39+ models. Pay only on days you use it — no subscription required.
Free to start · No credit card required to explore
Get Started Free