human
Minimum K such that every substring of length atleast K contains a character c | This function checks if there exists some character which appears in all K length substrings.
Iterate over all possible characters.
stores the last occurrence.
set answer as true.
No occurrence found of current character in first substring of length K.
Check for every last substring of length K where last occurr - ence exists in substring.
If last occ is not present in substring.
current character is K amazing.
This function performs binary search over the answer to minimise it.
Check if answer is found try to minimise it.
Driver Code"
Solution in Python:
 What is a code to minimum K such that every substring of length atleast K contains a character c and the other steps required?
assistant
#Here is code to minimum K such that every substring of length atleast K contains a character c and the other steps required.
 def check ( s , K ) :
	for ch in range ( 0 , 26 ) :
		c = chr ( 97 + ch )
		last = - 1
		found = True
		for i in range ( 0 , K ) :
			if s [ i ] == c :
				last = i
		if last == - 1 :
			continue
		for i in range ( K , len ( s ) ) :
			if s [ i ] == c :
				last = i
			if last <= ( i - K ) :
				found = False
				break
		if found :
			return 1
	return 0
def binarySearch ( s ) :
	low , high , ans = 1 , len ( s ) , None
	while low <= high :
		mid = ( high + low ) >> 1
		if check ( s , mid ) :
			ans , high = mid , mid - 1
		else :
			low = mid + 1
	return ans
if __name__ == " _ _ main _ _ " :
	s = " abcde "
	print ( binarySearch ( s ) )
	s = " aaaa "
	print ( binarySearch ( s ) )