Problem · String
Vowel Substring Game
Learn this problemProblem statement
You are given an array datasets of strings. For each string, two engineers play a turn-based game by repeatedly removing substrings under the following rules:
- Alex moves first and may remove any substring containing an odd number of vowels
- Chris moves next and may remove any substring containing an even number of vowels
- They continue alternating turns in the same manner
- Both play optimally
- The player who removes the last valid substring wins
Note:
- Vowels are
'a','e','i','o', and'u'
For each string, determine which engineer wins and return the result accordingly.
Function
determineWinners(datasets: String[]) → String[]Examples
Example 1
datasets = ["git", "dry"]return = ["Alex", "Chris"]Given n = 2 and datasets = ["git", "dry"]
- For the
datasets[0] = "git", Alex removes the entire string, leaving it empty. Since no valid moves are left, Chris cannot make a move, and Alex performs the final removal. - For the
datasets[1] = "dry", the string contains no vowels. Since Alex cannot make any moves, Chris is considered to have made the final removal.
Hence the answer is ["Alex", "Chris"].
Example 2
datasets = ["lgzpc", "lchxlo", "xnwzg"]return = ["Chris", "Alex", "Chris"]Sample Input For Custom Testing
| STDIN | FUNCTION |
|---|---|
| |
Sample Output
Chris
Alex
ChrisExplanation
Chris takes the first and third datasets which contain no vowels. Since Alex cannot make a move, Chris is considered to have made the final valid removal.
In the second dataset, datasets[1] = "lchxlo", there is exactly one vowel. Alex removes the entire string.
Constraints
1 ≤ n ≤ 1001 ≤ |datasets[i]| ≤ 10^5- All strings in the datasets consist of lowercase English letters only.