Tap here to switch tabs
Problem
Submissions

Problem: The Wording Game

med
30 min
Try to solve the The Wording Game problem.

Statement

Alice and Bob are playing a game using two arrays of strings, a and b, both sorted in lexicographically ascending order.

Alice starts the game by playing her lexicographically smallest word, which is a[0].

After the initial move, players take turns alternately, starting with Bob. On a player’s turn, they must choose a word from their own array that has not been played yet, satisfying both of the following conditions:

  • The word must be strictly lexicographically greater than the last played word.

  • The first character of the word must either be identical to the first character of the last played word, or be the alphabetical character immediately following it.

The first player who cannot make a valid move loses the game.

Assuming both players play optimally, return true if Alice wins the game, and false otherwise.

Constraints:

  • 1≤1 \leq a.length, b.length ≤105\leq 10^5

  • a[i] and b[i] consist only of lowercase English letters.

  • a and b are sorted in lexicographically ascending order.

  • All words across a and b combined are distinct.

  • The sum of the lengths of all words in a and b combined does not exceed 10610^6.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: The Wording Game

med
30 min
Try to solve the The Wording Game problem.

Statement

Alice and Bob are playing a game using two arrays of strings, a and b, both sorted in lexicographically ascending order.

Alice starts the game by playing her lexicographically smallest word, which is a[0].

After the initial move, players take turns alternately, starting with Bob. On a player’s turn, they must choose a word from their own array that has not been played yet, satisfying both of the following conditions:

  • The word must be strictly lexicographically greater than the last played word.

  • The first character of the word must either be identical to the first character of the last played word, or be the alphabetical character immediately following it.

The first player who cannot make a valid move loses the game.

Assuming both players play optimally, return true if Alice wins the game, and false otherwise.

Constraints:

  • 1≤1 \leq a.length, b.length ≤105\leq 10^5

  • a[i] and b[i] consist only of lowercase English letters.

  • a and b are sorted in lexicographically ascending order.

  • All words across a and b combined are distinct.

  • The sum of the lengths of all words in a and b combined does not exceed 10610^6.