dsa2 min read
Find Leaves of Binary Tree
Collect leaves by height (distance from leaf) repeatedly, returning all leaves at each height level.
Read →
1575 articles
Collect leaves by height (distance from leaf) repeatedly, returning all leaves at each height level.
Count nodes in a complete binary tree in O(log^2 n) by comparing left and right heights to identify full subtrees.
Find minimum seconds to collect all apples in a tree by DFS: include a subtree path only if it contains apples.
Find the maximum |a - b| for any ancestor-descendant pair by tracking min and max values along each root-to-leaf path.
Find the longest zigzag path in a binary tree where you alternate left-right directions at each step.