Depth-First-Search
LeetCode 1379: Find a Corresponding Node of a Binary Tree in a Clone of That Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 1379 note: walk both trees in lockstep; when the original reaches target, the clone’s node at the same position is the answer, comparing node identity
LeetCode 337: House Robber III
·2 mins
LeetCode
Medium
Dynamic-Programming
Tree
Depth-First-Search
Binary-Tree
LeetCode 337 note: tree DP where each node returns the best (rob it, skip it) pair; not robbing alternate levels
LeetCode 695: Max Area of Island
·2 mins
LeetCode
Medium
Array
Depth-First-Search
Breadth-First-Search
Union-Find
LeetCode 695 note: DFS each unvisited 1 to measure its island and keep the maximum; cells are the integer 1, not a string
LeetCode 417: Pacific Atlantic Water Flow
·3 mins
LeetCode
Medium
Array
Depth-First-Search
Breadth-First-Search
Matrix
LeetCode 417 note: walk inward from each ocean’s shore to cells no lower than the current one; cells reached from both oceans are the answer
LeetCode 133: Clone Graph
·1 min
LeetCode
Medium
Hash-Table
Depth-First-Search
Breadth-First-Search
Graph
LeetCode 133 note: during DFS map each old node to its copy and return the existing copy when revisited, avoiding infinite recursion; an empty graph returns None
LeetCode 98: Validate Binary Search Tree
·3 mins
LeetCode
Medium
Tree
Depth-First-Search
Binary-Search-Tree
Binary-Tree
LeetCode 98 note: every node has a valid range (low, high); going left the upper bound becomes the node and going right the lower bound does; comparing parent and child is not enough
LeetCode 230: Kth Smallest Element in a BST
·1 min
LeetCode
Medium
Tree
Depth-First-Search
Binary-Search-Tree
Binary-Tree
LeetCode 230 note: a BST’s in-order traversal is ascending, so stop an iterative in-order walk at the k-th node
LeetCode 199: Binary Tree Right Side View
·2 mins
LeetCode
Medium
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 199 note: in a level-order traversal, each level’s rightmost node is what you see from the right
LeetCode 1448: Count Good Nodes in Binary Tree
·1 min
LeetCode
Medium
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 1448 note: pass the path maximum down during DFS; a node is good when its value is at least that maximum
LeetCode 79: Word Search
·3 mins
LeetCode
Medium
Array
String
Backtracking
Depth-First-Search
LeetCode 79 note: backtrack from every cell, matching the next character in four directions with visited cells marked temporarily and restored; prune early with character counts
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