Vowels Substring Game

Alice and Bob are playing a game on a string s.

They take turns removing a non-empty substring from the current string, and Alice always moves first.

The rule for choosing a substring is:

  • Alice must remove a substring that contains an odd number of vowels.
  • Bob must remove a substring that contains an even number of vowels.

The vowels are: 'a', 'e', 'i', 'o', and 'u'.

After removing the chosen substring, the remaining left and right parts join together to form the new string.

The player who cannot make a valid move on their turn loses the game.

Return true if Alice wins assuming both players play optimally, otherwise return false.

Example 1:

Input: s = "abcde"

Output: true

Explanation:

Alice can remove the substring "a" which contains 1 vowel, so her move is valid.

The remaining string becomes "bcde".

Now Bob must remove a substring with an even number of vowels.

He can remove "b" because it contains 0 vowels, which is even.

The remaining string becomes "cde".

Alice can then remove "e" which contains 1 vowel.

Eventually, Bob will run out of valid moves first.

So, the answer is true.

Example 2:

Input: s = "bcdfg"

Output: false

Explanation:

The string contains no vowels.

So every substring has 0 vowels.

Alice must remove a substring with an odd number of vowels, but no such substring exists.

Hence, Alice cannot make her first move, so she loses.

Now Your Turn!

Pick the correct output for the given input

Input: s = "ae"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consists only of lowercase English letters.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
bool doesAliceWin(string s) {
// Your code goes here
}
};
Test Case

Input:

S