Ctrl K

Pruning Duel on a Growing Tree

Hard
A gardener grows a binary tree in stages: - at stage 0 there is no tree at all; - at stage 1 it is a single node; - at stage s ≥ 2 it is a root whose left subtree is the stage s - 2 tree and whose right subtree is the stage s - 1 tree. Two gardeners play on the tree of stage stage, taking turns. On a turn, a gardener picks any remaining node and cuts it off together with everything growing below it. Whoever has to cut the root loses. Return True if the player who moves first wins when both play optimally, and False otherwise.
Example 1
stage=3 → True

The first player cuts the leaf below the root's right child. Exactly two leaves remain: the second player cuts one, the first cuts the other, and the second is left with only the root.

Example 2
stage=1 → False

The tree is a lone root, so the first player has to cut it right away.

Example 3
stage=7 → False
Constraints
  • 1 ≤ stage ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOther Orders for the Same Search Tree HardCounting Search Tree Shapes MediumHeaviest Path in a Tree HardThief and Guard HardFewest Guards on a Tree Hard
loading Python…
Input
stage=3
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.