human
Maximum score possible by removing substrings made up of single distinct character | Function to check if the string s consists of a single distinct character or not.
Function to calculate the maximum score possible by removing substrings.
If string is empty.
If length of string is 1.
Store the maximum result.
Try to remove all substrings that satisfy the condition and check for resultant string after removal.
Store the substring { s [ i ] , . . , s [ j ] }.
Check if the substring contains only a single distinct character.
Return the maximum score.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to maximum score possible by removing substrings made up of single distinct character and the other steps required.
 def isUnique ( s ) :
	return True if len ( set ( s ) ) == 1 else False
def maxScore ( s , a ) :
	n = len ( s )
	if n == 0 :
		return 0
	if n == 1 :
		return a [ 0 ]
	mx = - 1
	for i in range ( n ) :
		for j in range ( i , n ) :
			sub = s [ i : j + 1 ]
			if isUnique ( sub ) :
				mx = max ( mx , a [ len ( sub ) - 1 ] + maxScore ( s [ : i ] + s [ j + 1 : ] , a ) )
	return mx
if __name__ == " _ _ main _ _ " :
	s = "011"
	a = [ 1 , 3 , 1 ]
	print ( maxScore ( s , a ) )