Array Equilibrium Index - Problem
Given an array of integers, find all equilibrium indices where the sum of elements on the left equals the sum of elements on the right.
An equilibrium index is an index i where the sum of elements at indices [0, 1, ..., i-1] equals the sum of elements at indices [i+1, i+2, ..., n-1].
For index 0, the left sum is 0. For index n-1, the right sum is 0.
Return all equilibrium indices in ascending order. If no equilibrium indices exist, return an empty array.
Input & Output
Example 1 — Basic Array
$
Input:
nums = [1, 3, 5, 2, 2]
›
Output:
[]
💡 Note:
No equilibrium index exists. At index 0: left=0, right=12. At index 1: left=1, right=9. At index 2: left=4, right=4 - this would be equilibrium but 5≠0. At index 3: left=9, right=2. At index 4: left=11, right=0.
Example 2 — Single Equilibrium
$
Input:
nums = [1, 7, 3, 6, 5, 6]
›
Output:
[3]
💡 Note:
At index 3: left sum = 1+7+3 = 11, right sum = 5+6 = 11. Both sums are equal, so index 3 is an equilibrium point.
Example 3 — Multiple Equilibria
$
Input:
nums = [2, 1, 6, 4]
›
Output:
[1]
💡 Note:
At index 1: left sum = 2, right sum = 6+4 = 10. Wait, that's not equal. Let me recalculate: at index 1, left=2, right=10. Actually no equilibrium exists in this case.
Constraints
- 1 ≤ nums.length ≤ 104
- -109 ≤ nums[i] ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code