Skip to main content

Equilibrium Index

Challenge on lesson: Checkpoint — Arrays

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** Given n numbers, print the smallest index i (0-based) such that the sum of elements before i equals the sum of elements after i. If no such index exists, print -1. **Input:** Line 1: n (1 ≤ n ≤ 10^5). Line 2: n numbers (−10^9..10^9). **Output:** One integer. **Example:** 4 / 1 7 3 6 → 1 (left of index 1: 1; right: 3+6=9? no — 1+7=8 vs 3+6=9... careful: left of index 1 is {1} sum 1, right is {3,6} sum 9. Try index 2: left {1,7} = 8, right {6} = 6. None → -1. Use 5 / 2 1 3 1 2: index 2 → left {2,1}=3, right {1,2}=3 → 2.)

Back to lesson: Checkpoint — Arrays