60. Equilibrium Index
MediumPrefix Sum
Find the first (smallest) 0-based index i such that the sum of elements before i equals the sum of elements after i. Print -1 if none exists.
Input format
Line 1: n Line 2: n integers
Output format
The index, or -1.
Example 1
Input
7 -7 1 5 2 -4 3 0
Output
3
Example 2
Input
3 1 2 3
Output
-1
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…