Find the player with least 0 s after emptying a Binary String by removing non | Function to find the player who wins the game ; Stores total count of 0 s in the string ; Stores count of consecutive 1 s ; Stores Nim - Sum on count of consecutive 1 s ; Stores length of the string ; Traverse the string ; If the current character is 1 ; Update cntConOne ; Update nimSum ; Update cntConOne ; Update cntZero ; Update nimSum ; If countZero is an even number ; nimSum is not 0 ; If nimSum is zero ; Driver Code
def FindwinnerOfGame ( S ) : NEW_LINE INDENT cntZero = 0 NEW_LINE cntConOne = 0 NEW_LINE nimSum = 0 NEW_LINE N = len ( S ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( S [ i ] == '1' ) : NEW_LINE INDENT cntConOne += 1 NEW_LINE DEDENT else : NEW_LINE INDENT nimSum ^= cntConOne NEW_LINE cntConOne = 0 NEW_LINE cntZero += 1 NEW_LINE DEDENT DEDENT nimSum ^= cntConOne NEW_LINE if ( cntZero % 2 == 0 ) : NEW_LINE INDENT print ( " Tie " ) NEW_LINE DEDENT elif ( nimSum ) : NEW_LINE INDENT print ( " player ▁ 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " player ▁ 2" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = "0110011" NEW_LINE FindwinnerOfGame ( S ) NEW_LINE DEDENT