Given a word and a text, return the count of the occurrences of anagrams of the word in the text. For eg. word is “for” and the text is “forxxorfxdofr”, anagrams of “for” wi
o(n) solution in Python
def check(s1,s2):
function takes in s1 as the text and s2 as the text to be checked from here for
c=0
n=len(s2)
ck=sorted(s2)
mk=''.join(ck)
this loop will pick from s till the length of s2 that is 'for'
for i,item in enumerate(s1):
if s1[i] in mk:
p=s1[i:i+n]
jk=sorted(p)
er=''.join(jk)
now just comparing the both sorted strings if they are equal then they were anagram
if er == mk:
c+=1
return c