Problem of the day
Let’s say the array ‘A’ = [1, 3, 1, 5], then if we select index ‘2’, the sum of the prefix is ‘1’, and the sum of the suffix is 1 + 5 = 6. Since the sum is not the same, hence index ‘2’ is not a beautiful index.
First-line contains ‘T’, denoting the number of Test cases.
For each Test case:
The first line contains an integer, ‘N’, denoting the length of the array ‘A’.
The following line contains an array ‘A’ of ‘N’ space-separated integers.
For each test case, you have to print an integer denoting the leftmost beautiful index. If there are no beautiful indexes, then print ‘-1’.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 10^5
-10^9 <= A[i] <= 10^9, for 1 <= i <= ‘N’
Note- Sum of ‘N’ over all test cases does not exceed 10^5.
Time Limit: 1 sec
2
3
1 1 1
3
1 2 3
2
-1
For test case 1:
Index ‘2’ is the leftmost beautiful index. The left sum is 1 and the right sum is also 1.
For test case 2:
No index is beautiful.
2
6
1 7 3 6 5 6
3
2 1 -1
4
1