Problem · String

Vowel Substring Game

Learn this problem
MediumAkuna Capital logoAkuna CapitalINTERNOA

Problem 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"]

  1. 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.
  2. 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

STDINFUNCTION
3
lgzpc
lchxlo
xnwzg
datasets[] size n
datasets = ["lgzpc", "lchxlo", "xnwzg"]

Sample Output

Chris
Alex
Chris

Explanation

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 ≤ 100
  • 1 ≤ |datasets[i]| ≤ 10^5
  • All strings in the datasets consist of lowercase English letters only.

More Akuna Capital problems

drafts saved locally
public String[] determineWinners(String[] datasets) {
  // write your code here
}
datasets["git", "dry"]
expected["Alex", "Chris"]
checking account