Problem:https://www.hackerrank.com/challenges/two-strings/problem

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.

Sample Code:


def twoStrings(s1, s2):
    flag=False
    for c in s1:
        if c in s2:
            flag=True
            break
    if flag:
        return ('YES')
    else:
        return ('NO')

Explanation:

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top