• + 0 comments

    Java:

    public static String twoStrings(String s1, String s2) {
      boolean[] charPresence = new boolean[26]; // a to z
    
      // Mark characters present in the array
      for (char c : s1.toCharArray()) {
        charPresence[c - 'a'] = true;
      }
    
      // Check if any character in the second string exists in the array
      for (char c : s2.toCharArray()) {
        if (charPresence[c - 'a']) {
          return "YES"; // Common character found
        }
      }
    
      return "NO"; // No common character found
    }