File tree Expand file tree Collapse file tree 1 file changed +92
-0
lines changed Expand file tree Collapse file tree 1 file changed +92
-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
+
5
+ class Codechef
6
+ {
7
+ static class FastReader
8
+ {
9
+ BufferedReader br ;
10
+ StringTokenizer st ;
11
+
12
+ public FastReader ()
13
+ {
14
+ br = new BufferedReader (new
15
+ InputStreamReader (System .in ));
16
+ }
17
+
18
+ String next ()
19
+ {
20
+ while (st == null || !st .hasMoreElements ())
21
+ {
22
+ try
23
+ {
24
+ st = new StringTokenizer (br .readLine ());
25
+ }
26
+ catch (IOException e )
27
+ {
28
+ e .printStackTrace ();
29
+ }
30
+ }
31
+ return st .nextToken ();
32
+ }
33
+
34
+ int nextInt ()
35
+ {
36
+ return Integer .parseInt (next ());
37
+ }
38
+
39
+
40
+ long nextLong ()
41
+ {
42
+ return Long .parseLong (next ());
43
+ }
44
+
45
+ double nextDouble ()
46
+ {
47
+ return Double .parseDouble (next ());
48
+ }
49
+
50
+ String nextLine ()
51
+ {
52
+ String str = "" ;
53
+ try
54
+ {
55
+ str = br .readLine ();
56
+ }
57
+ catch (IOException e )
58
+ {
59
+ e .printStackTrace ();
60
+ }
61
+ return str ;
62
+ }
63
+ }
64
+ public static void main (String [] args ) throws java .lang .Exception {
65
+ FastReader sc =new FastReader ();
66
+ int t =sc .nextInt ();
67
+ while (t -->0 ) {
68
+ int l =sc .nextInt ();
69
+ String s =sc .next ();
70
+ int ones =0 ,zero =0 ;
71
+ int flag =0 ;
72
+ for (int i =0 ;i <l ;i ++) {
73
+ if (s .charAt (i )=='1' ) {
74
+ ones ++;
75
+ }
76
+ if (s .charAt (i )=='0' ) {
77
+ zero ++;
78
+ }
79
+ if (ones >=zero ) {
80
+ flag =1 ;
81
+ break ;
82
+ }
83
+ }
84
+ if (flag ==1 ) {
85
+ System .out .print ("YES\n " );
86
+ }
87
+ else {
88
+ System .out .print ("NO\n " );
89
+ }
90
+ }
91
+ }
92
+ }
You can’t perform that action at this time.
0 commit comments