human
Longest substring where all the characters appear at least K times | Set 3 | Function to find the length of the longest substring.
Store the required answer.
Create a frequency map of the characters of the string.
Store the length of the string.
Traverse the string , s.
Increment the frequency of the current character by 1.
Stores count of unique characters.
Find the number of unique characters in string.
Iterate in range [ 1 , unique ].
Initialize frequency of all characters as 0.
Stores the start and the end of the window.
Stores the current number of unique characters and characters occuring atleast K times.
New unique character.
New character which occurs atleast k times.
Expand window by incrementing end by 1.
Check if this character is present atleast k times.
Check if this character is unique.
Shrink the window by incrementing start by 1.
If there are curr_unique characters and each character is atleast k times.
Update the overall maximum length.
Print the answer ;"
How can the above be solved in Python?

What is a code to longest substring where all the characters appear at least K times and the other steps required?
assistant
#Here is code to longest substring where all the characters appear at least K times and the other steps required.
 def longestSubstring ( s , k ) :
	ans = 0
	freq = [ 0 ] * 26
	n = len ( s )
	for i in range ( n ) :
		freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
	unique = 0
	for i in range ( 26 ) :
		if ( freq [ i ] != 0 ) :
			unique += 1
	for curr_unique in range ( 1 , unique + 1 ) :
		Freq = [ 0 ] * 26
		start , end = 0 , 0
		cnt , count_k = 0 , 0
		while ( end < n ) :
			if ( cnt <= curr_unique ) :
				ind = ord ( s [ end ] ) - ord ( ' a ' )
				if ( Freq [ ind ] == 0 ) :
					cnt += 1
				Freq [ ind ] += 1
				if ( Freq [ ind ] == k ) :
					count_k += 1
				end += 1
			else :
				ind = ord ( s [ start ] ) - ord ( ' a ' )
				if ( Freq [ ind ] == k ) :
					count_k -= 1
				Freq [ ind ] -= 1
				if ( Freq [ ind ] == 0 ) :
					cnt -= 1
				start += 1
			if ( ( cnt == curr_unique ) and ( count_k == curr_unique ) ) :
				ans = max ( ans , end - start )
	print ( ans )
/ * Driver Code * /
S = " aabbba "
K = 3
longestSubstring ( S , K )