Alice and Bob each have a lexicographically sorted array of strings named
a
andb
respectively.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
a
andb
, returntrue
if Alice can win knowing that both players play their best, andfalse
otherwise.A word
w
is closely greater than a wordz
if the following conditions are met:
w
is lexicographically greater thanz
.- If
w1
is the first letter ofw
andz1
is the first letter ofz
,w1
should either be equal toz1
or be the letter afterz1
in 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
s
is lexicographically greater than a stringt
if in the first position wheres
andt
differ, strings
has 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 { |