Fundamentals · Easy · Free
Compute height of a binary tree — recursive definition.
FresherFundamentalsData Structures & Algorithms
Tree height
java
int height(TreeNode n) {
if (n == null) return -1; // or 0 depending on definition
return 1 + Math.max(height(n.left), height(n.right));
}Clarify empty tree height 0 vs -1—consistency matters.
Balanced tree height O(log n); skewed O(n).