Solution Review: Find Max in Binary Tree

Let’s take a detailed look at the previous challenge’s solution.

Solution

We’ll solve this problem by recursively traversing the nodes of the binary tree. First, we’ll find the respective maximum values in the left and right subtree of a node. Then we’ll compare these values with the value of the current node. Finally, we’ll return the largest of these three values. We can code this solution as follows:

Solution code

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.