root of a binary search tree: for every node, all values in its left subtree are smaller than its own value and all values in its right subtree are larger. You also get a number rank.
Return the value that would stand in position rank if you listed all the tree's values in ascending order (counting from 1).
As a follow-up, think about what you would do if the tree changed often and this query came in all the time.root=tree_node([20, 10, 30, 5, 15, None, 40]), rank=4 → 20
In ascending order the values are 5, 10, 15, 20, 30, 40. The fourth one is 20.
root=tree_node([7, None, 9, 8]), rank=1 → 7
The root 7 is the smallest, since it has no left subtree.
root=tree_node([20, 10, 30, 5, 15, None, 40]), rank=4
20
Run checks the first 3 tests in your browser. Submit checks all 43 tests on the server, hidden ones included.