Post-order

3 articles

dsa6 min read

Distribute Coins in Binary Tree — LC 979 Post-Order Flow Analysis

LC 979 Distribute Coins in Binary Tree asks for minimum moves to give each node exactly one coin. The O(n) solution tracks coin excess flowing through each edge via post-order DFS — a pattern tested at Amazon and Google that elegantly converts a counting problem into a flow problem.

Read →
dsa5 min read

Find Leaves of Binary Tree — LC 366 Height-Based Grouping

LC 366 Find Leaves of Binary Tree groups nodes by their height (distance from the nearest leaf) using a post-order DFS — a problem asked at Amazon and LinkedIn that reveals an elegant alternative to iterative leaf removal.

Read →