Tree
LeetCode 102: Binary Tree Level Order Traversal
·2 mins
LeetCode
Medium
Tree
Breadth-First-Search
Binary-Tree
LeetCode 102 note: BFS one whole level at a time, building the next level from the current one; an empty tree returns an empty list
LeetCode 1022: Sum of Root To Leaf Binary Numbers
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 1022 note: on the way down double the current number and add the node’s bit, adding it to the total at a leaf
LeetCode 993: Cousins in Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 993 note: cousins share a depth but not a parent; record x’s and y’s depth and parent during DFS and compare
LeetCode 965: Univalued Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 965 note: every value must equal the root’s; compare values while recursing, not the booleans the recursion returns
LeetCode 938: Range Sum of BST
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Search-Tree
Binary-Tree
LeetCode 938 note: prune with the BST order, going only right below low and only left above high, adding nodes inside the range
LeetCode 897: Increasing Order Search Tree
·1 min
LeetCode
Easy
Stack
Tree
Depth-First-Search
Binary-Search-Tree
LeetCode 897 note: in-order traversal appending nodes to a right-only chain with left children cleared; keep the dummy separate from the moving tail
LeetCode 872: Leaf-Similar Trees
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 872 note: collect leaves left to right with DFS; BFS collects level by level, which is not left-to-right order
LeetCode 783: Minimum Distance Between BST Nodes
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Search-Tree
LeetCode 783 note: a BST’s in-order is ascending, so the minimum difference is between in-order neighbors; remember the previous value and compare
LeetCode 703: Kth Largest Element in a Stream
·1 min
LeetCode
Easy
Tree
Design
Binary-Search-Tree
Heap-Priority-Queue
LeetCode 703 note: keep a min-heap of size k; its top is the k-th largest
LeetCode 700: Search in a Binary Search Tree
·1 min
LeetCode
Easy
Tree
Binary-Search-Tree
Binary-Tree
LeetCode 700 note: go left when the node is larger, right when smaller, and return the node when found
LeetCode 671: Second Minimum Node In a Binary Tree
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 671 note: the root is the minimum; the second minimum is the smallest value larger than the root, and only subtrees equal to the root need searching
LeetCode 653: Two Sum IV - Input is a BST
·2 mins
LeetCode
Easy
Hash-Table
Two-Pointers
Tree
Depth-First-Search
LeetCode 653 note: traverse while keeping a set of seen values; finding k - val in it means a pair exists