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
During depth-first traversal, update diameter as leftHeight + rightHeight at each node and return max subtree height.
Each node contributes a candidate diameter through its left and right heights.
Updated Feb 2026