Alice and Bob each have a lexicographically sorted array of strings named
aandbrespectively.They are playing a wording game with the following rules:
- On each turn, the current player should play a word from their list such that the new word is closely greater than the last played word; then it’s the other player’s turn.
- If a player can’t play a word on their turn, they lose.
Alice starts the game by playing her lexicographically smallest word.
Given
aandb, returntrueif Alice can win knowing that both players play their best, andfalseotherwise.A word
wis closely greater than a wordzif the following conditions are met:
wis lexicographically greater thanz.- If
w1is the first letter ofwandz1is the first letter ofz,w1should either be equal toz1or be the letter afterz1in the alphabet.- For example, the word
"care"is closely greater than"book"and"car", but is not closely greater than"ant"or"cook".A string
sis lexicographically greater than a stringtif in the first position wheresandtdiffer, stringshas a letter that appears later in the alphabet than the corresponding letter int. If the firstmin(s.length, t.length)characters do not differ, then the longer string is the lexicographically greater one.
1 | class Solution { |