Given a list of integers, find the leftmost pivot index. The pivot index is the index where the sum of all numbers strictly to the left equals the sum of all numbers strictly to the right.
If no such index exists, return -1. Return -1 for null or empty input.
Examples:
Input: nums = [1, 7, 3, 6, 5, 6]
Output: 3
Explanation: Left sum of index 3 is 1 + 7 + 3 = 11. Right sum is 5 + 6 = 11. Equal, so return 3.
Input: nums = [1, 2, 3]
Output: -1
Explanation: No index has equal left and right sums.
Input: nums = [2, 1, -1]
Output: 0
Explanation: Left sum of index 0 is 0 (no elements to the left). Right sum is 1 + -1 = 0. Equal, so return 0.
Input: nums = []
Output: -1
Explanation: Empty list returns -1.
Input: nums = null
Output: -1
Explanation: Null input returns -1.
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay September 2026 (Sep 1–15)Sponsored by FLXBL
Contest runs September 1 - 15. Complete challenges to climb the leaderboard!
1st & 2nd: Salesforce certification exam voucher — see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.