DIY: Number of Matching Subsequences
Solve the interview question "Number of Matching Subsequences" in this lesson.
We'll cover the following
Problem statement
Given a string, ss
, and a list of words, words
, find the number of words[i]
that are a subsequence of ss
.
Input
The input will be a string, ss
, and a list of strings, words
. The following is an example input:
ss = "abcde"
words = ["a", "bb", "acd", "ace"]
Output
The output will be the number of subsequences of ss
that exist in words
. For the above input, the output will be:
3
The words "a", "acd", "ace"
are subsequences of ss
, and their count is 3
.
Coding exercise
For this coding exercise, you need to implement the num_matching_subseq(ss, words)
function, where ss
is the string and words
is the list of strings. The function should return the number of subsequences of ss
present in words
.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.