Given a list of integers, find the equilibrium index where the sum of elements to the left equals the sum of elements to the right. The element at the equilibrium index is not included in either sum. Return -1 if no equilibrium index exists. Return -1 for null or empty input.

Examples:

Input: nums = (1, 3, 5, 2, 2) Output: 2 Explanation: Left sum = 1+3 = 4, Right sum = 2+2 = 4, equilibrium at index 2 Input: nums = (0, 1, -1) Output: 0 Explanation: Left sum = 0 (nothing to the left), Right sum = 1+(-1) = 0 Input: nums = (1, 2, 3) Output: -1 Explanation: No index where left sum equals right sum Input: nums = (5) Output: 0 Explanation: Single element always has equilibrium at index 0 Input: nums = null Output: -1 Explanation: Null input returns -1
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

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 June 2026

Contest runs June 1 - 30. Complete challenges to climb the leaderboard!

Only the 30 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