first and Ben holds second; both lists are in alphabetical order, and all words across the two lists are distinct.
The players take turns, each placing one word from their own list. The new word must **top** the last word played, w:
- it comes after w in dictionary (lexicographic) order;
- its first letter is either the same as the first letter of w or the letter right after it in the alphabet.
For example, dog tops cat and dig, but it does not top apple (a and d are too far apart) or door (which comes after dog).
Whoever cannot move loses. Anna goes first, and her opening move must be the alphabetically earliest word in her list.
Return True if Anna wins when both play perfectly, and False otherwise.first=['cat', 'dove'], second=['cow'] → True
Anna opens with cat, Ben tops it with cow (same letter, later in the dictionary), Anna answers with dove (d comes right after c). Ben has nothing left to play, so Anna wins.
first=['bell', 'cup'], second=['bird', 'dart'] → False
bell → bird → cup → dart. After dart Anna has no words left, so she loses.
first=['moon'], second=['apple', 'kite'] → True
Both of Ben's words start with letters before m, so he cannot top moon.
first=['cat', 'dove'], second=['cow']
True
Run checks the first 3 tests in your browser. Submit checks all 61 tests on the server, hidden ones included.