dsa1 min read
Binary Tree Level Order Traversal — BFS Queue
Return values grouped by level using BFS with a queue, processing each level in a batch loop.
Read →
1575 articles
Return values grouped by level using BFS with a queue, processing each level in a batch loop.
Traverse a binary tree in zigzag level order by toggling insertion direction at each level.
Find the rightmost node at each level using BFS and taking the last element seen at each depth.
Collect all root-to-leaf paths with a given sum using DFS backtracking, appending and removing the current node.
Find the diameter (longest path between any two nodes) using a depth function that tracks the maximum path through each node.