-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.NonMatchingGame.java
48 lines (33 loc) · 1.21 KB
/
2.NonMatchingGame.java
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
47
import java.util.*;
class Codechef {
public static void main (String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
String sA = sc.next();
String sB = sc.next();
Set<Character> setA = new HashSet<>();
Set<Character> setB = new HashSet<>();
for (char c : sA.toCharArray()) {
setA.add(c);
}
for (char c : sB.toCharArray()) {
setB.add(c);
}
boolean validNameExists = false;
for (char c = 'a'; c <= 'z'; c++) {
if (!setA.contains(c) && !setB.contains(c)) {
validNameExists = true;
break;
}
}
if (validNameExists) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}