+1 vote
in Python by

Given two strings, string1 and string2, write a function is_subsequence to find out if string1 is a subsequence of string2.

1 Answer

0 votes
by
Hint: Notice that in the subsequence problem set, one string in this problem will need to be traversed to check for the values of the other string. In this case, it is string2.

The idea to solve this should then be simple. We traverse both strings from one side to the other side going from leftmost to rightmost. If we find a matching character, we move ahead in both strings. Otherwise, we move ahead only in string2.

Related questions

+1 vote
asked Oct 28, 2022 in Python by SakshiSharma
+1 vote
asked Oct 28, 2022 in Python by SakshiSharma
...