Binary-Tree
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
LeetCode 1161: Maximum Level Sum of a Binary Tree
·2 mins
LeetCode
Medium
Tree
Binary-Tree
Bfs
LeetCode 1161 note: pushing None into the next level creates a fake level with sum 0
LeetCode 2236: Root Equals Sum of Children
·1 min
LeetCode
Easy
Tree
Binary-Tree
LeetCode 2236 note: a warm-up, plus practice with C++ pointer access
LeetCode 958: Check Completeness of a Binary Tree
·2 mins
LeetCode
Medium
Tree
Binary-Tree
Bfs
LeetCode 958 note: completeness is a global property, so check with BFS whether any node follows the first gap
LeetCode 1008: Construct Binary Search Tree from Preorder Traversal
·3 mins
LeetCode
Medium
Tree
Bst
Binary-Tree
Recursion
LeetCode 1008 note: splitting the array is O(n^2); recursing with an upper bound is O(n)
LeetCode 236: Lowest Common Ancestor of a Binary Tree
·2 mins
LeetCode
Medium
Tree
Depth-First-Search
Binary-Tree
Binary-Lifting
LeetCode 236 note: recursion returns whichever of p or q a subtree contains; finding something on both sides means they split here, so this node is the LCA
LeetCode 2331: Evaluate Boolean Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 2331 note: leaves are 0 or 1 and internal nodes are 2 for OR and 3 for AND, evaluated in post-order
LeetCode 222: Count Complete Tree Nodes
·2 mins
LeetCode
Medium
Binary-Search
Bit-Manipulation
Tree
Binary-Tree
LeetCode 222 note: in a complete tree, equal leftmost depths on both sides mean one side is perfect, counted as 2^h - 1, for O(log² n)
LeetCode 129: Sum Root to Leaf Numbers
·2 mins
LeetCode
Medium
Tree
Depth-First-Search
Binary-Tree
LeetCode 129 note: on the way down multiply the current number by 10 and add the node’s value, adding it to the total at a leaf
LeetCode 117: Populating Next Right Pointers in Each Node II
·2 mins
LeetCode
Medium
Linked-List
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 117 note: connect next pointers level by level with BFS; for a non-perfect tree, looking only at the neighbour’s children breaks the chain
LeetCode 113: Path Sum II
·2 mins
LeetCode
Medium
Backtracking
Tree
Depth-First-Search
Binary-Tree
LeetCode 113 note: backtrack with the current path and store a copy at a leaf whose total matches; values can be negative, so no early pruning
LeetCode 107: Binary Tree Level Order Traversal II
·1 min
LeetCode
Medium
Tree
Breadth-First-Search
Binary-Tree
LeetCode 107 note: a normal level-order traversal reversed at the end gives bottom-up order