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 October 2026 (Oct 16–31)Sponsored by FLXBL

Contest runs October 16 - 31. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 16 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In