human
Queries to calculate difference between the frequencies of the most and least occurring characters in specified substring | Function to find difference between maximum and minimum frequency of a character in given range.
Stores length of string.
Stores count of queries.
Iterate over the characters of the string.
Stores l - value of a query.
Stores r - value of a query.
Store count of every character laying in range [ l , r ].
Update frequency of current character.
Stores maximum frequency of characters in given range.
Stores minimum frequency of characters in given range.
Iterate over all possible characters of the given string.
Update mx.
If ( j + ' a ' ) is present.
Difference between max and min.
Driver Code.
Given string.
Given queries.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to queries to calculate difference between the frequencies of the most and least occurring characters in specified substring and the other steps required.
 def maxDiffFreq ( queries , S ) :
	N = len ( S )
	Q = len ( queries )
	for i in range ( Q ) :
		l = queries [ i ] [ 0 ] - 1
		r = queries [ i ] [ 1 ] - 1
		freq = [ 0 ] * 26
		for j in range ( l , r + 1 ) :
			freq [ ord ( S [ j ] ) - ord ( ' a ' ) ] += 1
		mx = 0
		mn = 99999999
		for j in range ( 26 ) :
			mx = max ( mx , freq [ j ] )
			if ( freq [ j ] ) :
				mn = min ( mn , freq [ j ] )
		print ( mx - mn )
if __name__ == " _ _ main _ _ " :
	S = " abaabac "
	queries = [ [ 2 , 6 ] , [ 1 , 7 ] ]
	maxDiffFreq ( queries , S )