File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .*;
2+ import java .lang .*;
3+ import java .io .*;
4+ class GFG
5+ {
6+ public static void main (String [] args )
7+ {
8+ //code
9+ Scanner s = new Scanner (System .in );
10+ int t = s .nextInt ();
11+
12+ while (t -- > 0 ){
13+ int n = s .nextInt ();
14+ int a [] = new int [n ];
15+
16+ int rightSum = 0 ;
17+ for (int i = 0 ; i < n ; i ++){
18+ a [i ] = s .nextInt ();
19+ rightSum += a [i ];
20+ }
21+
22+ if (n == 1 ){
23+ System .out .println (1 );
24+ continue ;
25+ }
26+
27+ int leftSum = 0 ;
28+ boolean flag = false ;
29+
30+ for (int i = 0 ; i < n ; i ++){
31+ rightSum -= a [i ];
32+
33+ if (leftSum == rightSum ){
34+ System .out .println (i +1 );
35+ flag = true ;
36+ break ;
37+ }
38+
39+ leftSum += a [i ];
40+ }
41+
42+ if (!flag ) System .out .println (-1 );
43+
44+ }
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments