LeetCode Problem

How to Solve Vowels Game in a String

In the Vowels Game in a String, analyze the string to count vowels and apply optimal turn-based logic. Alice starts first, and the first player unable to make a move loses. Use a combination of string traversal and simple math to quickly decide whether Alice can force a win or if Bob will inevitably win.

GhostInterview Help

Need help with Vowels Game in a String without spending extra time grinding it?

GhostInterview can read Vowels Game in a String from a screenshot, generate the answer path, explain the complexity, and support solver-first interview workflows when you need direct help fast.

Screenshot Input

Capture the prompt fast instead of rewriting the problem by hand.

Answer + Complexity

Get the solution path, trade-offs, and complexity summary in one pass.

Stealth Workflow

Stay outside captured layers on supported screen-share workflows.

Problem #3227Math plus StringReviewed 2026-03-08
Difficulty
Medium
Primary pattern
Math plus String
Answer-first problem summary
Step-by-step approach and complexity
GhostInterview solver workflow

In the Vowels Game in a String, analyze the string to count vowels and apply optimal turn-based logic. Alice starts first, and the first player unable to make a move loses. Use a combination of string traversal and simple math to quickly decide whether Alice can force a win or if Bob will inevitably win.

Problem Statement

Alice and Bob play a game on a given lowercase string s. They take turns removing vowels, and the first player unable to move loses. Both players play optimally.

You must determine whether Alice can guarantee a win given the starting string. Consider the positions of vowels, potential moves, and the total length of s to decide the winner efficiently.

Examples

Example 1

Input: s = "leetcoder"

Output: true

Alice can win the game as follows:

Example 2

Input: s = "bbcd"

Output: false

There is no valid play for Alice in her first turn, so Alice loses the game.

Constraints

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

Solution Approach

Count Vowels Efficiently

Iterate through the string s and count all vowels. This helps determine the number of potential moves and establishes if Alice has any first-move options.

Apply Turn-Based Logic

Use the total vowel count to simulate optimal moves: if the count is zero at Alice's first turn, Bob wins. Otherwise, alternate turns until one player cannot move, applying math to skip unnecessary simulations.

Return Winner

Based on the analysis, return true if Alice can force a win and false if Bob will win. This ensures a direct, efficient solution without iterating through all game states.

Complexity Analysis

MetricValue
TimeDepends on the final approach
SpaceDepends on the final approach

Time complexity depends on traversing the string once to count vowels, giving O(n). Space complexity is O(1) since only counters are needed.

What Interviewers Usually Probe

  • Check if the candidate identifies counting vowels as the key first step.
  • Observe if the candidate considers the failure mode when the string has no vowels.
  • Look for recognition that optimal play can be predicted using simple math rather than full simulation.

Common Pitfalls or Variants

Common pitfalls

  • Failing to check if the initial string has zero vowels, leading to incorrect winner prediction.
  • Overcomplicating the game simulation instead of using vowel count and turn logic.
  • Ignoring edge cases with single-character strings or strings with all consonants.

Follow-up variants

  • Change the winning condition to removing consonants instead of vowels and analyze the impact on optimal strategy.
  • Use a string with alternating vowels and consonants to see how move sequences affect the winner.
  • Introduce a rule limiting moves per turn to 2 vowels, requiring adjusted math for optimal play.

How GhostInterview Helps

  • GhostInterview highlights vowel positions and counts to instantly determine feasible moves for Alice.
  • It identifies optimal play paths without simulating every game state, saving time during interviews.
  • The tool explains the exact pattern of math plus string needed to predict the winner reliably.

Topic Pages

FAQ

What is the main strategy to win the Vowels Game in a String?

Count vowels and apply turn-based logic; Alice wins if she has a first-move advantage and Bob wins otherwise.

How does the math plus string pattern apply here?

Vowel counting is the math part, string traversal is the string part, and combining them predicts the winner efficiently.

What should I do if the string has no vowels?

Alice cannot move, so Bob wins immediately. This edge case is critical for correct results.

Can this approach handle very long strings?

Yes, because counting vowels requires a single pass with O(n) time and O(1) space.

Are there variations of this game that change the optimal strategy?

Yes, altering the type of removable characters or limiting moves per turn changes the math calculation for winning.

GhostInterview Solver

Need direct help with Vowels Game in a String instead of spending more time grinding it?

Download GhostInterview when you want a LeetCode solver, not another long practice loop. Capture Vowels Game in a String from a screenshot, get the answer path and complexity, and use supported stealth workflows that stay outside captured layers.

Screenshot Input

Capture the prompt fast instead of rewriting the problem by hand.

Answer + Complexity

Get the solution path, trade-offs, and complexity summary in one pass.

Stealth Workflow

Stay outside captured layers on supported screen-share workflows.