Sort by

recency

|

2276 Discussions

|

  • + 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
    def twoStrings(s1, s2):
        return 'YES' if len(set(s1)&set(s2)) else 'NO'
    
  • + 0 comments

    My solution is partially correct:

    def twoStrings(s1, s2):
        # Write your code here
        msg = 'NO'
    
        for cs1 in s1:
            for cs2 in s2:
                if cs1==cs2:
                    msg = 'YES'
        return msg
    
  • + 0 comments

    Using c#

    public static string twoStrings(string s1, string s2)
    {
      HashSet<char> hashS1 = new HashSet<char>(s1);
    
      foreach(char c in s2) {
    	if (hashS1.Contains(c)) {
    	  return "YES";
    	}
      }
      return "NO";
    }
    
  • + 0 comments

    short solution:

    def twoStrings(s1, s2):
        # Write your code here
        myset = set()
        flag = 'NO'
        
        for i in range(len(s1)):
            myset.add(s1[i])
    
        for i in range(len(s2)):
            if s2[i] in myset:
                flag = 'YES'
                break
    
        return flag