I am trying to check if there exists a subsequence of a string s2 that is the string s1. The only caveat is the subsequence of s2 that is s1 cannot be a substring of s2.
Subsequence:
abac : bc is a subsequence of the string
abcd : bc is a substring and a subsequence of the string
Examples:
s1 = "devil", s2 = "devilishly" True as devil is a subsequence using the last 'l' before the y to make it not a substring
s1 = "devil", s2 = "devilish" False, as devil is a subsequence but is also a substring of devilish
def isSubsequence(str1,str2):
i,j = 0, 0
while j<len(str1) and i<len(str2):
if str1[j] == str2[i]:
j = j+1
i = i + 1
return j==len(str(1))
I believe this is how to check if a string1 is a subsequence of string2. However, I am not sure how to add the extra property that string1 is not a subword of string2.
Anyone have any ideas on how to go about doing this.