given two strings s1 and pattern
find how many substrings in s that is equal to string pattern
i knew the algo for this is sliding window, but im havin a difficult time coding it up, any help is appriciated.
def sliding(s1):
# sliding window
l, r = 0, 0
i = 0
count = 0
print(s1)
while r < len(s1):
if i + 1 == len(pattern):
count += 1
i = 0
char = s1[r]
# if valid char
if i + 1 < len(pattern) and char == pattern[i]:
# proceed with this, it is good
i += 1
# not valid char
else:
# check if i + 1 == len(pattern) cuz if so it is 1 cell found
i = 0
l += 1
while l < r and s1[l] != pattern[i]:
l += 1
print(s1[r],r, l)
r += 1
return count