✅easiest-soln | Adobe🔥| well-explained👁️
If you found my answer helpful, please consider giving it an upvote\uD83D\uDE0A\n#ReviseWithArsh #6Companies30Days Challenge 2023\nChallenge Company 3 : Adobe\n
## If you found my answer helpful, please consider giving it an upvote\uD83D\uDE0A\n***#ReviseWithArsh #6Companies30Days Challenge 2023\nChallenge Company 3 : Adobe\nQ7.Number of Matching Subsequences***\n\n# Complexity\n- Time complexity: O(NM) where N is the length of the given string and M is the number of words in the vector.\n\n- Space complexity: O(M) where M is the number of words in the vector.\n\n# Code\n```\nclass Solution {\npublic:\n    // function to check if a given word is a subsequence of string s\n    bool isSubsequence(string s, string word) {\n    // Edge case: if the length of s is less than the length of word, return false\n    if(s.length() < word.length()) return false;\n    int sIndex = 0, wIndex = 0; // sIndex and wIndex are pointers for s and word respectively\n    \n    // iterate through both s and word\n    while(sIndex < s.length() && wIndex < word.length()) {\n        // if s[sIndex] is equal to word[wIndex], increment both pointers\n        if(s[sIndex] == word[wIndex]) {\n            sIndex++;\n            wIndex++;\n        } else {\n            sIndex++;\n        }\n    }\n    \n    // if wIndex reaches the end of word, it means it is a subsequence of s\n    return (wIndex == word.length());\n}\n\nint numMatchingSubseq(string s, vector<string>& words) {\n    int matchCount = 0; // variable to keep track of the number of matching subsequences\n    \n    unordered_map<string, int> cache; // hash map to store previously checked words and their result\n    \n    // iterate through all words in the given vector\n    for(auto &word : words) {\n        // if the word has already been checked, add the result to matchCount\n        if(cache.count(word)) {\n            matchCount += cache[word];\n        } else {\n            // if the word has not been checked yet, check it and add the result to matchCount\n            matchCount += cache[word] = isSubsequence(s, word);\n        }\n    }\n    return matchCount;\n    }\n};\n```
['C++']