We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 72ef2f9 commit 7d44e67Copy full SHA for 7d44e67
Point_Balanced.java
@@ -0,0 +1,34 @@
1
+import java.util.*;
2
+public class Point_Balanced {
3
+ public static void main(String[] args) {
4
+ Scanner in = new Scanner(System.in);
5
+ int T = in.nextInt();
6
+ while(T-->0){
7
+ int n = in.nextInt();
8
+ long a[] = new long[n];
9
+ long sum = 0;
10
+ for(int i=0;i<n;i++){
11
+ a[i] = in.nextLong();
12
+ sum += a[i];
13
+ }
14
+ boolean check = false;
15
+ if(n < 3)
16
+ System.out.println("-1");
17
+ else{
18
+ long sTmp = a[0];
19
+ for(int i=1;i<n;i++){
20
+ if(sTmp == sum-sTmp-a[i]){
21
+ check = true;
22
+ System.out.println(i+1);
23
+ break;
24
25
26
+ sTmp += a[i];
27
28
29
+ if(check == false)
30
31
32
33
34
+}
0 commit comments