human
Write me a code to minimum value of K such that each substring of size K has the given character and the other steps required given the following:
Minimum value of K such that each substring of size K has the given character | Function to find the minimum value of K such that char c occurs in all K sized substrings of string S.
Store the string length.
Store difference of lengths of segments of every two consecutive occurrences of c.
Stores the maximum difference.
Store the previous occurence of char c.
Check if the current character is c or not.
Stores the difference of consecutive occurrences of c.
Update previous occurrence of c with current occurence.
Comparing diff with max.
If string doesn 't contain c.
Return max.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum value of K such that each substring of size K has the given character and the other steps required.
 def findK ( s , c ) :
	n = len ( s )
	diff = 0
	max = 0
	prev = 0
	for i in range ( 0 , n ) :
		if ( s [ i ] == c ) :
			diff = i - prev
			prev = i
			if ( diff > max ) :
				max = diff
	if ( max == 0 ) :
		return - 1
	return max
if __name__ == " _ _ main _ _ " :
	S = " abdegb "
	ch = ' b '
	print ( findK ( S , ch ) )