chain and the root of a binary tree.
Check whether the tree has a path that goes strictly downward (from some node to one of its children, then to one of that child's children, and so on) whose values match the values of chain exactly, in order, from its first node to its last.
The path may start at any node, not only the root, and may stop anywhere, not only at a leaf. Return True if such a path exists and False otherwise.chain=list_node([3, 1]), root=tree_node([5, 3, 8, None, 1]) → True
The tree has the downward path 3 → 1, from the root's left child to its right child.
chain=list_node([5, 8, 2]), root=tree_node([5, 3, 8, None, 1]) → False
The path 5 → 8 exists, but node 8 has no children, so 2 cannot follow.
chain=list_node([5, 3, 1]), root=tree_node([5, 3, 8, None, 1]) → True
The path may also start at the root: 5 → 3 → 1.
chain=list_node([3, 1]), root=tree_node([5, 3, 8, None, 1])
True
Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.