human
Number of substrings having an equal number of lowercase and uppercase letters | Function to find the count of substrings having an equal number of uppercase and lowercase characters.
Stores the count of prefixes having sum S considering uppercase and lowercase characters as 1 and - 1.
Stores the count of substrings having equal number of lowercase and uppercase characters.
Stores the sum obtained so far.
If the character is uppercase.
Otherwise.
If currsum is o.
If the current sum exists in the HashMap prevSum.
Increment the resultant count by 1.
Update the frequency of the current sum by 1.
Return the resultant count of the subarrays.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to number of substrings having an equal number of lowercase and uppercase letters and the other steps required.
 def countSubstring ( S , N ) :
	prevSum = { }
	res = 0
	currentSum = 0
	for i in range ( N ) :
		if ( S [ i ] >= ' A ' and S [ i ] <= ' Z ' ) :
			currentSum += 1
		else :
			currentSum -= 1
		if ( currentSum == 0 ) :
			res += 1
		if ( currentSum in prevSum ) :
			res += ( prevSum [ currentSum ] )
		if currentSum in prevSum :
			prevSum [ currentSum ] += 1
		else :
			prevSum [ currentSum ] = 1
	return res
if __name__ == ' _ _ main _ _ ' :
	S = " gEEk "
	print ( countSubstring ( S , len ( S ) ) )