Number of matching Subsequence || C++ || Very Simple and Explained solution
Solution-1->\npre-compute all the subsequence of s and store in map, then count the word which are in words TLE.\n## Solution-2->\nbrute force and match every w
## Solution-1->\npre-compute all the subsequence of s and store in map, then count the word which are in words TLE.\n## Solution-2->\nbrute force and match every words[i] to s => TLE (as length of s and words both are large)\n\nNow we can optimize the 2nd method, the key is to observe that the word length is at most 50 but the array size is very large thus there must be some repetition of words.\nHence we will use some memoization (to store the words which we have checked already) in an unordered-map\n### and whenever we get a previously visited word just update the res and continue\n\n```\nint numMatchingSubseq(string s, vector<string>& words) {\n        unordered_map<string, bool> m;\n        int res = 0;\n        for(auto word : words){\n            if(m.find(word) != m.end()){res += m[word]; continue;}\n            int i=0, j=0;\n            while(i<word.length() && j<s.length()){\n                if(s[j] == word[i])i++,j++;\n                else j++;\n            }\n            m[word] = i==word.length();\n            res += i==word.length();\n        }\n        return res;\n    }\n```\n# plz upvote if you find it helpful
[]