human
Minimum K such that every substring of length at least K contains a character c | Set | Function to find minimum value of K such that there exist atleast one K amazing character.
Stores the answer.
Update the S.
Iterate over the characters in range [ a , z ].
Stores the last index where c appears.
Stores the maximum possible length.
Update S.
Iterate over characters of string S.
If S [ i ] is equal to c.
Stores the distance between positions of two same c.
Update max_len.
Update the value of prev.
Update the value of ans.
Return the answer.
Driver Code.
Given Input.
Function Call"
Solution in Python:
assistant
#Here is code to minimum K such that every substring of length at least K contains a character c and the other steps required.
 def MinimumLengthSubstring ( S , N ) :
	ans = N
	S = "0" + S + "0"
	S = [ i for i in S ]
	for c in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
		prev = 0
		max_len = 0
		S [ 0 ] = chr ( c )
		S [ N + 1 ] = chr ( c )
		for i in range ( 1 , N + 2 ) :
			if ( S [ i ] == chr ( c ) ) :
				len = i - prev
				max_len = max ( max_len , len )
				prev = i
		ans = min ( ans , max_len )
	return ans
if __name__ == ' _ _ main _ _ ' :
	S = " abcde "
	N = len ( S )
	print ( MinimumLengthSubstring ( S , N ) )