Question
Max Element in a Binary Search Tree
You are given the root of a Binary Search Tree (BST). Your task is to determine the maximum element present in the BST.
Note: A Binary Search Tree (BST) is a binary tree in which, for every node, all values in its left subtree are strictly less than the node’s value, and all values in its right subtree are strictly greater than the node’s value.
Note: A Binary Search Tree (BST) is a binary tree in which, for every node, all values in its left subtree are strictly less than the node’s value, and all values in its right subtree are strictly greater than the node’s value.
Input
User Task
Since this is a functional problem, you do not need to handle input or output. Your task is to complete the function find_max(), which takes the root node as the input parameter.
Custom Input
The first line of input contains an integer, N, representing the number of nodes in the tree.
The next line consists of space-separated integers denoting the level order traversal of the tree, where non-negative values represent node values, and -1 indicates a null node.
Note: Once a node is marked as -1, no further information about its children is provided.
Since this is a functional problem, you do not need to handle input or output. Your task is to complete the function find_max(), which takes the root node as the input parameter.
Custom Input
The first line of input contains an integer, N, representing the number of nodes in the tree.
The next line consists of space-separated integers denoting the level order traversal of the tree, where non-negative values represent node values, and -1 indicates a null node.
Note: Once a node is marked as -1, no further information about its children is provided.
Output
Return an integer that represents the Max Element in a BST.
Example
Input
9
44 27 65 16 33 57 -1 -1 19 -1 -1 -1 -1 17 21
Output
65
Explanation
The following image depicts the given BST:

9
44 27 65 16 33 57 -1 -1 19 -1 -1 -1 -1 17 21
Output
65
Explanation
The following image depicts the given BST:
