Arrays

  • + 1 comment

    Why does the following code time out on the largest few inputs? Isn't it also O(n)?

    void checkMagazine(vector<string> magazine, vector<string> note) {
        unordered_multiset<string> magazineSet (magazine.begin(), magazine.end());
        unordered_multiset<string> noteSet (note.begin(), note.end());
        for (string word: note) {
            if(noteSet.count(word) > magazineSet.count(word)) {
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }