@@ -0,0 +1,2027 @@
+package algorithms.strings;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * You are given two strings, A and B. Find if there is a substring that appears%0D%0A * in both A and B.%0D%0A * %0D%0A * Input Format: %0D%0A * Several test cases will be given to you in a single file. The first line of%0D%0A * the input will contain a single integer T, the number of test cases.%0D%0A * %0D%0A * Then there will be T descriptions of the test cases. Each description%0D%0A * contains two lines. The first line contains the string A and the second line%0D%0A * contains the string B.%0D%0A * %0D%0A * Output Format: %0D%0A * For each test case, display YES (in a newline), if there is a common%0D%0A * substring. Otherwise, display NO.%0D%0A * %0D%0A * Constraints: %0D%0A * All the strings contain only lowercase Latin letters.%0D%0A * 1 %3C= T %3C= 10%0D%0A * 1 %3C= %7CA%7C,%7CB%7C %3C= 105%0D%0A * %0D%0A * Sample Input: %0D%0A * 2%0D%0A * hello%0D%0A * world%0D%0A * hi%0D%0A * world%0D%0A * %0D%0A * Sample Output: %0D%0A * YES%0D%0A * NO%0D%0A */%0D%0Apublic class TwoStrings %7B%0D%0A%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A        %0D%0A        Scanner sc = new Scanner(System.in);%0D%0A        %0D%0A        int numCases = sc.nextInt();%0D%0A        %0D%0A        for (int i = 0; i %3C numCases; i++) %7B%0D%0A            String str1 = sc.next();%0D%0A            String str2 = sc.next();%0D%0A            %0D%0A            HashSet%3CCharacter%3E chars = new HashSet%3C%3E();%0D%0A            %0D%0A            char%5B%5D str1ToChars = str1.toCharArray();%0D%0A            for (int j = 0; j %3C str1ToChars.length; j++) %7B%0D%0A                chars.add(new Character(str1ToChars%5Bj%5D));%0D%0A            %7D%0D%0A            %0D%0A            boolean commonChar = false;%0D%0A            int index = 0;%0D%0A            %0D%0A            while (index %3C str2.length()) %7B%0D%0A                if (chars.contains(str2.charAt(index))) %7B%0D%0A                    commonChar = true;%0D%0A                    break;%0D%0A                %7D%0D%0A                index++;%0D%0A            %7D%0D%0A            if (commonChar) %7B%0D%0A                System.out.println(%22YES%22);%0D%0A            %7D else %7B%0D%0A                System.out.println(%22NO%22);%0D%0A            %7D%0D%0A        %7D%0D%0A        sc.close();%0D%0A    %7D%0D%0A%7D

Add TwoStrings