You are given the following:
Two players A and B play a game turn by turn in which one player can have either of the following moves in his turn:
The player unable to make a move loses the game.
Task
Predict the winner of the game if both play optimally and A to start's the game. The game may end in a draw if the game may go on forever.
Note
'a', 'e', 'i', 'o' ,'u' are vowels and others are consonants in lowercase alphabets.
Example
Assumptions
Approach
In 1st turn A will remove a consonant either 'b' or 'c'. In the 2nd turn, B will remove the remaining consonant left. In 3rd turn, nothing is left so A loses the game.
Function description
Complete the solve function provided in the editor. This function takes the following 2 parameters and returns the winner of the game if both play optimally:
Input:
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
Output
For each test case, print a single character A or B denoting the winner of the game. If there is a draw print D in a new line.
Constraints
1≤T≤1031≤N≤104
Note: String consists of only lower case alphabets.
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
The first line represents the number of test cases, T = 3.
For test case 1
Approach
The string is "bcd". Since all are consonants no conversion is possible. Hence in 3 turns the game will definitely finish. In 1st turn A will remove a consonant. In the second turn, B will remove one, while in 3rd again A will remove the last consonant left. In 4th turn, nothing is left so B loses the game.
For test case 2
Approach
If A in his first turn converts 'a' to any of the consonants then from the next turn onwards the entire game is reduced to the removal of consonants only. As a whole, there will be 5 turns with A to start and finish hence A wins the game.
For test case 3
Approach
In this case entire string consists of only vowels. Even if one vowel is removed anyhow still nobody will convert the last vowel to a consonant. Hence most optimally the game ends in a draw.