human
Maximum length subsequence possible of the form R ^ N K ^ N | Function to calculate the maximum length of substring of the form R ^ nK ^ n.
Count no . Of R 's before a K.
Count no . Of K 's after a K.
Update maximum length.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to maximum length subsequence possible of the form R ^ N K ^ N and the other steps required.
 def find ( s ) :
	Max = j = countk = countr = 0
	table = [ [ 0 , 0 ] for i in range ( len ( s ) ) ]
	for i in range ( 0 , len ( s ) ) :
		if s [ i ] == ' R ' :
			countr += 1
		else :
			table [ j ] [ 0 ] = countr
			j += 1
	j -= 1
	for i in range ( len ( s ) - 1 , - 1 , - 1 ) :
		if s [ i ] == ' K ' :
			countk += 1
			table [ j ] [ 1 ] = countk
			j -= 1
		if min ( table [ j + 1 ] [ 0 ] , table [ j + 1 ] [ 1 ] ) > Max :
			Max = min ( table [ j + 1 ] [ 0 ] , table [ j + 1 ] [ 1 ] )
	return Max
if __name__ == " _ _ main _ _ " :
	s = " RKRRRKKRRKKKKRR "
	print ( find ( s ) )