DIY: Number of Matching Subsequences

Solve the interview question "Number of Matching Subsequences" in this lesson.

Problem statement

Given a string, s, and a list of words, words, find the number of words[i] that are a subsequence of s.

Input

The input will be a string, s, and a list of strings, words. The following is an example input:

s = "abcde"
words = ["a", "bb", "acd", "ace"]

Output

The output will be the number of subsequences of s that exist in words. For the above input, the output will be:

3

The words "a", "acd", "ace" are subsequences of s, and their count is 3.

Coding exercise

For this coding exercise, you need to implement the num_matching_subseq(s, words) function, where s is the string and words is the list of strings. The function should return the number of subsequences of s present in words.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.