root, the root of a binary search tree: for every node, all values in its left subtree are smaller than its own and all values in its right subtree are larger. All values are distinct.
Find the node whose value is key and return it, which means returning the whole subtree that grows from it. If there is no such node, return None.root=tree_node([20, 10, 30, 5, 15, 25]), key=10 → [10, 5, 15]
Node 10 is found and returned together with its children 5 and 15.
root=tree_node([20, 10, 30, 5, 15, 25]), key=17 → None
17 lies between 10 and 20, so it would be the right child of 15, and that spot is empty. The answer is None.
root=tree_node([8, None, 12, 9]), key=12 → [12, 9]
root is a valid search tree with distinct valuesroot=tree_node([20, 10, 30, 5, 15, 25]), key=10
[10, 5, 15]
Run checks the first 3 tests in your browser. Submit checks all 38 tests on the server, hidden ones included.