In a Publicis Sapient interview setting, implement a function that returns the maximum value stored in a binary search tree (BST). Use the BST property to solve the problem efficiently instead of scanning every node.
A BST is defined such that for every node, values in the left subtree are smaller and values in the right subtree are larger. Because of this property, the maximum value is always found at the rightmost node.
root, the root node of a binary search tree, or None for an empty treeNone if the tree is emptyExample 1
root = [8, 3, 10, 1, 6, null, 14]148, move right to 10, then right to 14. No further right child exists, so 14 is the maximum.Example 2
root = [5]50 <= number of nodes <= 10^5-10^9 <= Node.val <= 10^9None for an empty tree