Tree
LeetCode 987: Vertical Order Traversal of a Binary Tree
·2 mins
LeetCode
Hard
Tree
Binary-Tree
Bfs
Sorting
LeetCode 987 note: collect (col, row, val) triples, sort them, and group by column
LeetCode 2973: Find Number of Coins to Place in Tree Nodes
·3 mins
LeetCode
Hard
Dynamic-Programming
Tree-Dp
Depth-First-Search
Sorting
Heap
Tree
LeetCode 2973 note: the max product of three is either the three largest or the two smallest times the largest, so each subtree returns only its 2 smallest and 3 largest values, merged in post-order
LeetCode 1028: Recover a Tree From Preorder Traversal
·3 mins
LeetCode
Hard
Tree
Binary-Tree
Dfs
Stack
String
LeetCode 1028 note: a stack holds the path from the root to the current node, so its length is the depth
LeetCode 2509: Cycle Length Queries in a Tree
·2 mins
LeetCode
Hard
Tree
Binary-Tree
Lca
LeetCode 2509 note: in heap numbering the parent is v // 2, so climb the larger node until both meet at the LCA
LeetCode 1373: Maximum Sum BST in Binary Tree
·2 mins
LeetCode
Hard
Dynamic-Programming
Tree-Dp
Binary-Search-Tree
Depth-First-Search
Tree
LeetCode 1373 note: a post-order traversal returns (sum, min, max, is_bst); a node roots a BST when the left max < its value < the right min
LeetCode 1377: Frog Position After T Seconds
·3 mins
LeetCode
Hard
Tree
Dfs
Bfs
Graph
Probability
LeetCode 1377 note: undirected edges, seen must hold nodes, and an early arrival depends on whether the frog can still move
LeetCode 2421: Number of Good Paths
·3 mins
LeetCode
Hard
Tree
Union-Find
Graph
Sorting
LeetCode 2421 note: add nodes in increasing value order and count same-value nodes per Union-Find group
LeetCode 2603: Collect Coins in a Tree
·4 mins
LeetCode
Hard
Tree
Graph
Topological-Sort
LeetCode 2603 note: trim coin-free leaves, trim exactly two more layers, and walk each remaining edge twice
LeetCode 2196: Create Binary Tree From Descriptions
·2 mins
LeetCode
Medium
Tree
Binary-Tree
Hash-Map
LeetCode 2196 note: keep nodes in a dict and link them in one pass; the root is the only value that is nobody’s child
LeetCode 3820: Pythagorean Distance Nodes in a Tree
·2 mins
LeetCode
Medium
Tree
Bfs
Graph
LeetCode 3820 note: three BFS runs give every node’s distance to the three targets
LeetCode 865: Smallest Subtree with all the Deepest Nodes
·2 mins
LeetCode
Medium
Tree
Binary-Tree
Bfs
Dfs
Lca
LeetCode 865 note: BFS to the last level and climb together, or one DFS returning (depth, node)
LeetCode 1339: Maximum Product of Splitted Binary Tree
·2 mins
LeetCode
Medium
Tree
Binary-Tree
Dfs
LeetCode 1339 note: compute the total, enumerate every subtree sum, and leave the input untouched