human
Count substrings with each character occurring at most k times | Python 3 program to count number of substrings in which each character has count less than or equal to k ..
variable to store count of substrings ..
array to store count of each character ..
increment character count.
check only the count of current character because only the count of this character is changed . The ending point is incremented to current position only if all other characters have count at most k and hence their count is not checked . If count is less than k , then increase ans by 1..
if count is less than k , then break as subsequent substrings for this starting point will also have count greater than k and hence are reduntant to check ..
return the final count of substrings ..
Driver code"
Solution in Python:

What is a code to count substrings with each character occurring at most k times and the other steps required?
assistant
#Here is code to count substrings with each character occurring at most k times and the other steps required.
 def findSubstrings ( s , k ) :
	ans = 0
	n = len ( s )
	for i in range ( n ) :
		cnt = [ 0 ] * 26
		for j in range ( i , n ) :
			cnt [ ord ( s [ j ] ) - ord ( ' a ' ) ] += 1
			if ( cnt [ ord ( s [ j ] ) - ord ( ' a ' ) ] <= k ) :
				ans += 1
			else :
				break
	return ans
if __name__ == " _ _ main _ _ " :
	S = " aaabb "
	k = 2
	print ( findSubstrings ( S , k ) )