Back to course home
0% completed
Find maximum depth of subtree (medium)
Problem Statement
Given the root
node of a binary tree and an integer val
, find the maximum depth of the subtree that starts from the node with the value equal to val
. If the node with value val
doesn't exist in the tree, return 0
.
The depth of a node is defined as the number of edges on the longest path from the node to a leaf.
Examples
Example 1
- Input: root =
[3, 5, 4, 2, null, 1, null, 6]
, val =5
- Expected Output:
3
- Explanation: The subtree starting from the node with value
5
has nodes5
,2
, and6
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible