Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use DFS recursion where each leaf node returns height 1, and each internal node returns 1 plus the maximum height among its children. Also implement a BFS alternative that tracks depth level-by-level using a queue.
Recursively computing 1 + max(children heights) propagates the longest root-to-leaf path upward, while the BFS variant naturally discovers the maximum depth as it processes each level.
Updated Feb 2026