All Patterns
Pattern 7
Tree BFS
Process a tree level by level using a queue. At each level, snapshot the queue size so you know exactly how many nodes belong to that level.
Time
O(n)
Space
O(n)
Recognize it when
- Level-order traversal
- Minimum depth / shortest path in tree
- Right side view / left side view
- Average or sum per level
Progress0/5
0 solved0 attempted
Questions — ordered by difficulty
#102Medium
Binary Tree Level Order Traversal
Return the level-order (BFS) traversal of a binary tree as a list of lists.
treebfsqueue
#199Medium
Binary Tree Right Side View
Return the values of the nodes you can see from the right side of the tree (rightmost node per level).
treebfsdfs
#637Easy
Average of Levels in Binary Tree
Return the average value of nodes on each level of a binary tree.
treebfs
#111Easy
Minimum Depth of Binary Tree
Find the minimum depth — the shortest path from root to the nearest leaf node.
treebfsdfs
#103Medium
Binary Tree Zigzag Level Order Traversal
Return zigzag level order traversal: left→right, then right→left, alternating per level.
treebfsdeque