root with size nodes; size is odd, and the nodes are labelled with distinct numbers from 1 to size.
First, player one claims the node with value first_pick, then player two claims any other node. After that they take turns, player one first. On a turn a player claims one unclaimed node that is adjacent to a node they already own (the neighbours of a node are its left child, right child and parent). A player with no such node skips the turn. When neither can move, whoever owns more nodes wins.
You are player two. Return True if you can pick your first node so that you are sure to win, and False otherwise.root=tree_node([1, 2, 3, 4, 5, 6, 7]), size=7, first_pick=2 → True
By taking node 1, the second player gets the whole part of the tree above and to the right of 2 (nodes 1, 3, 6, 7): 4 nodes against 3.
root=tree_node([1, 2, 3, 4, 5, 6, 7]), size=7, first_pick=1 → False
The root splits the tree into two halves of 3 nodes. The second player can cut off only one of them and the first player takes the other: 3 against 4.
root=tree_node([3, 1, None, 2]), size=3, first_pick=1 → False
size is oddsize nodessizeroot=tree_node([1, 2, 3, 4, 5, 6, 7]), size=7, first_pick=2
True
Run checks the first 3 tests in your browser. Submit checks all 17 tests on the server, hidden ones included.