forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
64 lines (55 loc) · 1.31 KB
/
Solution.java
File metadata and controls
64 lines (55 loc) · 1.31 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
* Note: An empty string is always a sub-string
* @author srinath
*
*/
public class Solution {
//public static HashMap<String,String> h=new HashMap<String,String>();
public static String equal(String w1, String w2) {
HashMap<String,String> h=new HashMap<String,String>();
String w;
int a=w1.length();
int b=w2.length();
if(a>b){
w=w1;
w1=w2;
w2=w;
}
int seet=0;
for(int j=0;j<w2.length();j++){
String q2=w2.charAt(j)+"";
h.put(q2,q2);
}
// Display elements
for(int is=0;is<w1.length();is++){
String qq=w1.charAt(is)+"";
if(h.containsKey(qq)){
seet=1;
break;
}
}
if(seet==1){
return "YES";
}else{
return "NO";
}
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc= new Scanner(System.in);
int ic= sc.nextInt();
sc.nextLine();
String[] Output=new String[ic];
for(int i=0;i<ic;i++){
Output[i]= equal(sc.next(),sc.next());
}
for(int i=0;i<ic;i++){
System.out.println(Output[i]);;
}
}
}