← Tree Recursion

Pattern Recognition Drill

#36 — Height of a binary tree

Easy Trees

The Problem

Find the height of a binary tree.

What approach would you use?

Think about it before scrolling down.

Key Signals

Tree Recursion

Recurse on both children, return 1 + max(left, right). O(n) visiting all nodes.

Alt: Queue / BFS

Level-order traversal, count levels. Same O(n) but more complex code.

Common Trap

Clarify the height convention with the interviewer: edge-count vs node-count (off by one).

← #35 #37 →