c++ two approaches best explained why simple brute force will give TLE
\n1.simple brute force..this will give you tle because we may be recalculating same result over and over again.\nclass Solution {\npublic:\n    int numMatchingS
```\n1.simple brute force..this will give you tle because we may be recalculating same result over and over again.\nclass Solution {\npublic:\n    int numMatchingSubseq(string s, vector<string>& words) {\n        int count=0,k=s.size();\n      //just loop over words.\n      for(int i=0;i<words.size();i++)\n      {\n        int start1=0,start2=0;\n        string p=words[i];//p will store the string at index i in vector word.\n        int m=p.size();\n        //start matching the very first character of string s with that of p.\n        while(start1<k&&start2<m)\n        {\n          if(p[start2]==s[start1])// if it matches increment both start1 and start2 to check next match\n            start1++,start2++;\n          else// if it does not matches you need to increment index of string s only to check the next character of s with p.\n            start1++;\n        }if(start2==m)// if we reach the length of string p then this word in in our string s. so we increase our count by 1.\n          count++;\n      }return count;\n    }\n};\n//this will give you TIME LIMIT EXCEEDED because our input vector words can be very large \n2.modified brute force using map\nclass Solution {\npublic:\n    int numMatchingSubseq(string s, vector<string>& words) {\n        int count=0,k=s.size();\n      //we will be form map to count occurences of particular word to avoid re calculation and this will reduce time\n      unordered_map<string,int>mymap;\n      for(int i=0;i<words.size();i++)\n        mymap[words[i]]++;\n      for(auto x:mymap)\n      {\n        int start1=0,start2=0;\n        string p=x.first;\n        int m=p.size();\n        while(start1<k&&start2<m)\n        {\n          if(p[start2]==s[start1])\n            start1++,start2++;\n          else\n            start1++;\n        }if(start2==m)\n          count+=x.second;//if we reach the length of string p then this word in in our string s. so we increase our count by number of times it occured in words instead of increamenting by 1\n      }return count;\n    }\n};\ndo upvote if you find it useful...\n```
['C', 'C++']