Sort by

recency

|

2284 Discussions

|

  • + 0 comments

    Approach:

    1. Count the freq of the 1st string.
    2. Traverse the freq mapp and check whether it contains the atleast 1 same key(character)
    3. if yes --> return "YES"
    4. else -->return "NO"
  • + 0 comments

    Here is my one line Python solution!

    def twoStrings(s1, s2):
        return "NO" if len(set(s1).intersection(set(s2))) == 0 else "YES"
    
  • + 0 comments

    how to solve this proplem with kmp

  • + 0 comments

    Here is my simple c++ solution, video explanation here : https://youtu.be/xwLiYvExM6I

    string twoStrings(string s1, string s2) {
        map<char, int>mp;
        for(int i = 0; i < s1.size(); i++) mp[s1[i]] = 1;
        for(int i = 0; i < s2.size(); i++){
            if(mp[s2[i]]) return "YES";
        }
        return "NO";
    }
    
  • + 0 comments

    Version 1:

    def twoStrings(s1, s2):
        for char in s1:
            if char in s2:
                return "YES"
        return "NO"
    

    Version 2:

    def twoStrings(s1, s2):
        return "YES" if any(char in s2 for char in s1) else "NO"
    

    Version 3:

    def twoStrings(s1, s2):
        return "YES" if set(s1) & set(s2) else "NO"