Magicsheet logo

Vowels Game in a String

Medium
12.5%
Updated 8/1/2025

Asked by 1 Company

Vowels Game in a String

What is this problem about?

The Vowels Game in a String coding problem is a strategic challenge centered around two players, Alice and Bob, who take turns removing substrings from a given string. Alice starts first and can only remove a substring that contains an odd number of vowels. Bob, on the other hand, can only remove substrings containing an even number of vowels. The player who cannot make a move loses the game. The core task is to determine who will win assuming both players play optimally.

Why is this asked in interviews?

This problem is popular in Meta interviews because it combines string manipulation with basic game theory and logical reasoning. It tests whether a candidate can look past the complexity of "optimal play" and identify the underlying mathematical truth of the game. Often, what looks like a complex simulation can be reduced to a simple check of parity (odd vs. even), which reveals the candidate's ability to simplify problems.

Algorithmic pattern used

The Vowels Game in a String interview pattern relies heavily on Brainteaser and Math concepts. While it mentions substrings and game theory, the actual solution often boils down to checking the existence of vowels. In many variations of this game, if Alice has even a single move she can make (i.e., if there is at least one vowel in the string), she can strategically take a portion that leaves Bob in a losing position or just take the whole string if it satisfies her condition.

Example explanation

Imagine the string "leetcode". It contains 4 vowels ('e', 'e', 'o', 'e').

  • Alice needs a substring with an odd number of vowels.
  • Since 4 is even, she can't take the whole string. However, she can take a substring like "leetcod" which has 3 vowels (odd).
  • If the string was "bcd", there are 0 vowels. Alice cannot make her first move because 0 is not odd. In this case, Bob wins by default because Alice fails her first turn.
  • The logic usually simplifies to: if there is at least one vowel, Alice can always find an odd-vowel substring to start with and potentially win.

Common mistakes candidates make

Candidates often overcomplicate the problem by trying to use minimax algorithms or complex dynamic programming. While those are valid for many games, they are overkill here. Another mistake is miscounting vowels or forgetting to handle the case where the string has no vowels at all.

Interview preparation tip

Whenever you see a "game" problem in an interview, first try to play out small cases by hand. Look for a pattern that determines the winner regardless of the specific moves. Often, the win condition depends on a single property like the total count of a specific element being even or odd.

Similar Questions