-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNonAdjFlip.java
More file actions
39 lines (33 loc) · 1009 Bytes
/
Copy pathNonAdjFlip.java
File metadata and controls
39 lines (33 loc) · 1009 Bytes
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
package io.github.tahanima.codechef;
import java.util.Scanner;
/**
* @author tahanima
*/
public class NonAdjFlip {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
while (cases-- > 0) {
int n = scanner.nextInt();
String binaryStr = scanner.next();
boolean hasOne = binaryStr.charAt(0) == '1';
boolean hasAdjOnes = false;
for (int i = 1; i < n; i++) {
if (binaryStr.charAt(i) == '1') {
hasOne = true;
if (binaryStr.charAt(i - 1) == '1')
hasAdjOnes = true;
}
}
if (hasOne) {
if (hasAdjOnes) {
System.out.println(2);
} else {
System.out.println(1);
}
} else {
System.out.println(0);
}
}
}
}