You've successfully subscribed to The Poor Coder | Hackerrank Solutions
Great! Next, complete checkout for full access to The Poor Coder | Hackerrank Solutions
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Hackerrank - Two Strings Solution

Hackerrank - Two Strings Solution

Beeze Aal
Beeze Aal

Given two strings, determine if they share a common substring. A substring may be as small as one character.

For example, the words "a", "and", "art" share the common substring . The words "be" and "cat" do not share a substring.

Function Description

Complete the function twoStrings in the editor below. It should return a string, either YES or NO based on whether the strings share a common substring.

twoStrings has the following parameter(s):

  • s1, s2: two strings to analyze .

Input Format

The first line contains a single integer , the number of test cases.

The following  pairs of lines are as follows:

  • The first line contains string .
  • The second line contains string .


  • and  consist of characters in the range ascii[a-z].

Output Format

For each pair of strings, return YES or NO.

Sample Input


Sample Output



We have  pairs to check:

  1. , . The substrings  and  are common to both strings.
  2. , .  and  share no common substrings.

Solution in Python

def twoStrings(s1, s2):
    return "YES" if set(s1) & set(s2) else "NO"
for _ in range(int(input())):
    print(twoStrings(input(), input()))