human
Check if a string contains an anagram of another string as its substring | Function to check if string s2 contains anagram of the string s1 as its substring.
Stores frequencies of characters in substrings of s2.
Stores frequencies of characters in s1.
If length of s2 exceeds length of s1.
Store frequencies of characters in first substring of length s1len in string s2.
Perform Sliding Window technique.
If hashmaps are found to be identical for any substring.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if a string contains an anagram of another string as its substring and the other steps required.
 def checkAnagram ( s1 , s2 ) :
	s2hash = [ 0 for i in range ( 26 ) ]
	s1hash = [ 0 for i in range ( 26 ) ]
	s1len = len ( s1 )
	s2len = len ( s2 )
	if ( s1len > s2len ) :
		return False
	left = 0
	right = 0
	while ( right < s1len ) :
		s1hash [ ord ( s1 [ right ] ) - 97 ] += 1
		s2hash [ ord ( s2 [ right ] ) - 97 ] += 1
		right += 1
	right -= 1
	while ( right < s2len ) :
		if ( s1hash == s2hash ) :
			return True
		right += 1
		if ( right != s2len ) :
			s2hash [ ord ( s2 [ right ] ) - 97 ] += 1
		s2hash [ ord ( s2 [ left ] ) - 97 ] -= 1
		left += 1
	return False
if __name__ == ' _ _ main _ _ ' :
	s1 = " ab "
	s2 = " bbpobac "
	if ( checkAnagram ( s1 , s2 ) ) :
		print ( " YES " )
	else :
		print ( " No " )