Solution Review: Tree Depth
Let’s take a detailed look at the previous challenge’s solution.
We'll cover the following
Solution
We find the depth of a tree by recursively traversing the left and right child of the root. At each level of traversal, we calculate the depth of both left and right children. The greater depth among the left and right children is added by one (which is the depth of the current node). Finally, this value is returned.
Solution code
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.