|
| 1 | +# 3227. Vowels Game in a String [Rating: 1451.81] |
| 2 | + |
| 3 | +<p>Alice and Bob are playing a game on a string.</p> |
| 4 | + |
| 5 | +<p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li>On Alice's turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substring</span> from <code>s</code> that contains an <strong>odd</strong> number of vowels.</li> |
| 9 | + <li>On Bob's turn, he has to remove any <strong>non-empty</strong> <span data-keyword="substring">substring</span> from <code>s</code> that contains an <strong>even</strong> number of vowels.</li> |
| 10 | +</ul> |
| 11 | + |
| 12 | +<p>The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play <strong>optimally</strong>.</p> |
| 13 | + |
| 14 | +<p>Return <code>true</code> if Alice wins the game, and <code>false</code> otherwise.</p> |
| 15 | + |
| 16 | +<p>The English vowels are: <code>a</code>, <code>e</code>, <code>i</code>, <code>o</code>, and <code>u</code>.</p> |
| 17 | + |
| 18 | +<p> </p> |
| 19 | +<p><strong class="example">Example 1:</strong></p> |
| 20 | + |
| 21 | +<div class="example-block"> |
| 22 | +<p><strong>Input:</strong> <span class="example-io">s = "leetcoder"</span></p> |
| 23 | + |
| 24 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 25 | + |
| 26 | +<p><strong>Explanation:</strong><br /> |
| 27 | +Alice can win the game as follows:</p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li>Alice plays first, she can delete the underlined substring in <code>s = "<u><strong>leetco</strong></u>der"</code> which contains 3 vowels. The resulting string is <code>s = "der"</code>.</li> |
| 31 | + <li>Bob plays second, he can delete the underlined substring in <code>s = "<u><strong>d</strong></u>er"</code> which contains 0 vowels. The resulting string is <code>s = "er"</code>.</li> |
| 32 | + <li>Alice plays third, she can delete the whole string <code>s = "<strong><u>er</u></strong>"</code> which contains 1 vowel.</li> |
| 33 | + <li>Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.</li> |
| 34 | +</ul> |
| 35 | +</div> |
| 36 | + |
| 37 | +<p><strong class="example">Example 2:</strong></p> |
| 38 | + |
| 39 | +<div class="example-block"> |
| 40 | +<p><strong>Input:</strong> <span class="example-io">s = "bbcd"</span></p> |
| 41 | + |
| 42 | +<p><strong>Output:</strong> <span class="example-io">false</span></p> |
| 43 | + |
| 44 | +<p><strong>Explanation:</strong><br /> |
| 45 | +There is no valid play for Alice in her first turn, so Alice loses the game.</p> |
| 46 | +</div> |
| 47 | + |
| 48 | +<p> </p> |
| 49 | +<p><strong>Constraints:</strong></p> |
| 50 | + |
| 51 | +<ul> |
| 52 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 53 | + <li><code>s</code> consists only of lowercase English letters.</li> |
| 54 | +</ul> |
0 commit comments