Function to check if a string can be made empty by removing all subsequences of the form " GFG " or not
def findIfPossible ( N , str_ ) : NEW_LINE INDENT countG = 0 NEW_LINE countF = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if str_ [ i ] == ' G ' : NEW_LINE INDENT countG += 1 NEW_LINE DEDENT else : NEW_LINE INDENT countF += 1 NEW_LINE DEDENT DEDENT if 2 * countF != countG : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT else : NEW_LINE INDENT id = 0 NEW_LINE flag = True NEW_LINE for i in range ( N ) : NEW_LINE INDENT if str_ [ i ] == ' G ' : NEW_LINE INDENT countG -= 1 NEW_LINE id += 1 NEW_LINE DEDENT else : NEW_LINE INDENT countF -= 1 NEW_LINE id -= 1 NEW_LINE DEDENT if id < 0 : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT if countG < countF : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT DEDENT