human
What is a code to minimum characters to be replaced to remove the given substring and the other steps required given the following:
Minimum characters to be replaced to remove the given substring | Function to calculate minimum characters to replace.
mismatch occurs.
If all characters matched , i . e , there is a substring of ' a ' which is same as string ' b '.
increment i to index m - 1 such that minimum characters are replaced in ' a '.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum characters to be replaced to remove the given substring and the other steps required.
 def replace ( A , B ) :
	n , m = len ( A ) , len ( B )
	count , i = 0 , 0
	while i < n :
		j = 0
		while j < m :
			if i + j >= n or A [ i + j ] != B [ j ] :
				break
			j += 1
		if j == m :
			count += 1
			i += m - 1
		i += 1
	return count
if __name__ == " _ _ main _ _ " :
	str1 = " aaaaaaaa "
	str2 = " aaa "
	print ( replace ( str1 , str2 ) )