Count no . Of R 's before a K
for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' R ' : NEW_LINE INDENT countr += 1 NEW_LINE DEDENT else : NEW_LINE INDENT table [ j ] [ 0 ] = countr NEW_LINE j += 1 NEW_LINE DEDENT DEDENT j -= 1 NEW_LINE