#K69622. Find the Equilibrium Index
Find the Equilibrium Index
Find the Equilibrium Index
You are given an array of integers and your task is to find its equilibrium index. The equilibrium index of an array is an index i such that the sum of the elements on the left side of i is equal to the sum on its right side.
Formally, given an array \(a\) of length \(n\), find an index \(i\) (where \(0 \le i < n\)) such that \[ \sum_{j=0}^{i-1} a_j = \sum_{j=i+1}^{n-1} a_j \] If there are multiple equilibrium indices, output the smallest index. If no equilibrium index exists, output -1.
inputFormat
The first line contains an integer \(T\) representing the number of test cases. For each test case, the first line contains an integer \(N\) which is the size of the array. The following line contains \(N\) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single line with the equilibrium index. If no equilibrium index exists, output -1.
## sample2
5
1 3 5 2 2
4
1 2 3 4
2
-1
</p>