fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int t = scanner.nextInt(); // number of test cases
  9. while (t-- > 0) {
  10. int n = scanner.nextInt(); // length of s
  11. String s = scanner.next(); // binary string s
  12. String r = scanner.next(); // binary string r
  13.  
  14. // Check if we can perform the operation by finding adjacent differing bits
  15. boolean canPerformOperations = false;
  16.  
  17. // Traverse s and check for adjacent differing bits
  18. for (int i = 0; i < n - 1; i++) {
  19. if (s.charAt(i) != s.charAt(i + 1)) {
  20. canPerformOperations = true;
  21. break;
  22. }
  23. }
  24.  
  25. // If there's at least one adjacent differing pair, we can perform operations
  26. if (canPerformOperations) {
  27. System.out.println("YES");
  28. } else {
  29. System.out.println("NO");
  30. }
  31. }
  32.  
  33. scanner.close();
  34. }
  35. }
  36.  
Success #stdin #stdout 0.11s 56612KB
stdin
6
2
11
0
2
01
1
4
1101
001
6
111110
10000
6
010010
11010
8
10010010
0010010
stdout
NO
YES
YES
YES
YES
YES