Find the winner of the Game of removing odd or replacing even array elements | Function to evaluate the winner of the game ; Stores count of odd array elements ; Stores count of even array elements ; Traverse the array ; If array element is odd ; Otherwise ; If count of even is zero ; If count of odd is even ; If count of odd is odd ; If count of odd is odd and count of even is one ; Otherwise ; Driver code
def findWinner ( arr , N ) : NEW_LINE INDENT odd = 0 NEW_LINE even = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 1 ) : NEW_LINE INDENT odd += 1 NEW_LINE DEDENT else : NEW_LINE INDENT even += 1 NEW_LINE DEDENT DEDENT if ( even == 0 ) : NEW_LINE INDENT if ( odd % 2 == 0 ) : NEW_LINE INDENT print ( " Player ▁ 2" ) NEW_LINE DEDENT elif ( odd % 2 == 1 ) : NEW_LINE INDENT print ( " Player ▁ 1" ) NEW_LINE DEDENT DEDENT elif ( even == 1 and odd % 2 == 1 ) : NEW_LINE INDENT print ( " Player ▁ 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 1 , 9 , 7 ] NEW_LINE N = len ( arr ) NEW_LINE findWinner ( arr , N ) NEW_LINE DEDENT