Find the player to last modify a string such that even number of consonants and no vowels are left in the string | Function to find a winner of the game if both the player plays optimally ; Stores the count of vowels and consonants ; Traverse the string ; Check if character is vowel ; Increment vowels count ; Otherwise increment the consonants count ; Check if Player B wins ; Check if Player A wins ; Check if Player A wins ; If game ends in a Draw ; Given String s ; Function Call
def findWinner ( s ) : NEW_LINE INDENT vowels_count = 0 NEW_LINE consonants_count = 0 NEW_LINE p = len ( s ) NEW_LINE for i in range ( 0 , p ) : NEW_LINE INDENT if ( s [ i ] == ' a ' or s [ i ] == ' e ' or s [ i ] == ' i ' or s [ i ] == ' o ' or s [ i ] == ' u ' ) : NEW_LINE INDENT vowels_count = vowels_count + 1 NEW_LINE DEDENT else : NEW_LINE INDENT consonants_count = consonants_count + 1 NEW_LINE DEDENT DEDENT if ( vowels_count == 0 ) : NEW_LINE INDENT if ( consonants_count % 2 == 0 ) : NEW_LINE INDENT print ( " Player ▁ B " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Player ▁ A " ) NEW_LINE DEDENT DEDENT elif ( vowels_count == 1 and consonants_count % 2 != 0 ) : NEW_LINE INDENT print ( " Player ▁ A " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " D " ) NEW_LINE DEDENT DEDENT s = " abcd " NEW_LINE findWinner ( s ) NEW_LINE