Posted on

Description

Submission

#include <bits/stdc++.h>

using namespace std;

// Complete the twoStrings function below.
string twoStrings(string s1, string s2) {
    map<char, int> m;
    for(auto c: s1) {
        auto it = m.find(c);
        if(it == m.end()) {
            m.insert(make_pair(c, 1));
        }
    }

    for(char c: s2) {
        if(m.find(c) != m.end()) return "YES";
    }
    return "NO";
}

int main()
{
    ofstream fout(getenv("OUTPUT_PATH"));

    int q;
    cin >> q;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');

    for (int q_itr = 0; q_itr < q; q_itr++) {
        string s1;
        getline(cin, s1);

        string s2;
        getline(cin, s2);

        string result = twoStrings(s1, s2);

        fout << result << "\n";
    }

    fout.close();

    return 0;
}

Leave a Reply

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