Given a string s and an array of strings words, return the number of strings in words that are subsequences of s.
A string is a subsequence of s if it can be formed by deleting zero or more characters from s without changing the relative order of the remaining characters.
Constraints:
1≤ s.length ≤5∗104
1≤ words.length ≤5000
1≤ words[i].length ≤50
s and words[i] consist of only lowercase English letters.
Input: s = "abcde"-str, words = ["a","bb","acd","ace"]-List[str]
Output: 3-int
Explanation: "a", "acd", and "ace" are subsequences of "abcde", while "bb" is not (there aren’t two 'b' characters in order).
Input: s = "dsahjpjauf"-str, words = ["ahjpjau","ja","ahbwzgqnuk","tnmlanowax"]-List[str]
Output: 2-int
Explanation: "ahjpjau" and "ja" can be formed by deleting characters from s while keeping order, while the other two words require characters that don’t appear in the needed order (or at all).
Input: s = "aaaaa"-str, words = ["a","aa","aaa","aaaa","aaaaa","aaaaaa","b"]-List[str]
Output: 5-int
Explanation: The first five words, up to length 5, are subsequences, while "aaaaaa" is too long to fit and "b" doesn’t exist in s.
Input: s = "xyz"-str, words = ["x","y","z","xy","xz","yz","xyz","zx"]-List[str]
Output: 7-int
Explanation: All listed words except "zx" are subsequences. "zx" fails because 'z' appears after 'x' in s, so you can’t match 'z' then 'x' in order.
Input: s = "abacb"-str, words = ["ab","ac","ba","abc","aab","abb"]-List[str]
Output: 5-int
Explanation: "ab", "ac", "ba", "abc", and "aab" are subsequences, while "abb" is not (after matching 'a' then 'b', there is no remaining 'b' in the correct position).
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem: