Level-order traversal that counts completed levels. Every fully drained queue level bumps the depth counter.
Compute the maximum depth (height) of a binary tree using breadth-first search. The depth is the number of nodes along the longest root-to-leaf path. BFS expands the tree level-by-level; every time the queue finishes draining one full level, we increment the depth counter. When the queue is empty the counter holds the answer.
Push the root onto a FIFO queue, then repeat: take the size of the queue (that is the "level"), pop exactly that many nodes, and push their non-null children. After the inner loop the queue contains the next level only, never a mix. On the canvas: a dashed cyan ring means "sitting in the queue", a solid cyan node is the one being popped right now, green means drained, and the tinted band spans the level currently draining. It turns green, next to its number on the depth ruler, the moment that level is done.
Before draining the queue, snapshot its length. That snapshot tells you exactly how many pops belong to the current level, even though children of those pops get pushed back during the loop. Without this snapshot you would mix levels and lose the depth count.
Each iteration of the outer while loop corresponds to one full level. Bumping depth at the start of the iteration (or at the end, which is equivalent) means depth always equals the number of levels processed so far. When the queue is empty the outer loop exits and depth is the final answer.
You could also solve Maximum Depth with DFS (1 + max(left, right)), which uses O(h) recursion stack. BFS uses O(w) auxiliary space where w is the maximum width of the tree. For very wide, shallow trees DFS wins on memory; for very deep, narrow trees BFS wins. Either way, time is O(n).
This level-counting pattern generalises: replacing the depth counter with a list collector gives "Binary Tree Level Order Traversal"; replacing it with a parity check gives "Zigzag Level Order"; replacing it with a per-level rightmost selector gives "Binary Tree Right Side View".