Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created September 12, 2025 20:43
Show Gist options
  • Select an option

  • Save Ifihan/285538624791604e3f709c18d6b480d0 to your computer and use it in GitHub Desktop.

Select an option

Save Ifihan/285538624791604e3f709c18d6b480d0 to your computer and use it in GitHub Desktop.
Vowels Game in a String

Question

Approach

I observe that Alice can make a move iff the string contains at least one vowel, because she can always remove a single-letter substring that is a vowel (which has 1—odd—vowel). If there are no vowels, Alice has no valid first move and immediately loses. If there is at least one vowel, Alice can win: she can either delete the whole string if the total number of vowels is odd, or delete a suitable odd-vowel substring (e.g., any single vowel) to force a position where Bob has no winning reply. Therefore, the outcome reduces to a simple check—Alice wins iff the string contains any vowel.

Implementation

class Solution:
    def doesAliceWin(self, s: str) -> bool:
        V = set("aeiou")
        return any(ch in V for ch in s)

Complexities

  • Time: O(n)
  • Space: O(1)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment