forked from Bhavya1912/Hackerrank-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSherlockandArray.java
More file actions
46 lines (45 loc) · 1.19 KB
/
SherlockandArray.java
File metadata and controls
46 lines (45 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t--!=0){
int n = sc.nextInt();
int a[] = new int[n];
int sum = 0;
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
sum = sum + a[i];
}
int left=0;
int right=0;
int flag=0;
for(int i=0;i<n;i++){
if(i==0){
left = 0;
right = sum - a[0];
}
else if(i==n-1){
left = sum - a[0];
right = 0;
}
else{
left = left + a[i-1];
right = right - a[i];
}
if(left==right){
flag = 1;
break;
}
}
if(flag==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
}