Simple recursive solution without substr() function
It should be remembered that the substr() function has a time complexity of O(m), where \'m\' is the size of the substring to be found.\n\nThe idea behind the o
It should be remembered that the substr() function has a time complexity of O(m), where \'m\' is the size of the substring to be found.\n\nThe idea behind the optimization is to reduce the time taken by substr() function by maintaining an index, till which we have searched both the strings and using the string::find() method to search for the next character of words[i] in the string \'s\'.\n\n**Time taken - 116ms (Faster than 99.13%)\nSpace taken - 29.7MB (Less than 99.25%)**\n```\n// offset is the current index of string \'s\'\n// offSub is the current index of string \'sub\'\nbool isFound(string &s, string &sub, int offset, int offSub) {\n\tif(offSub == sub.size())\n\t\treturn 1;\n\tif(offset >= s.size())\n\t\treturn 0;\n\n\toffset = s.find(sub[offSub], offset);\n\t\n\t// if sub[offSub] not found, then return false\n\tif(offset == string::npos)\n\t\treturn 0;\n\n\treturn isFound(s, sub, offset+1, offSub+1);\n}\n\nint numMatchingSubseq(string &s, vector<string>& words) {\n\tint cnt = 0;\n\tfor(auto i: words)\n\t\t// start current indices of both strings from 0\n\t\tif(isFound(s, i, 0, 0))\n\t\t\tcnt++;\n\treturn cnt;\n}\n```\n**Any suggestions are welcome \uD83D\uDE00.\nPlease upvote the post if you like the solution approach.**
['Recursion']