Find the maximum area of any island in a binary grid using DFS that returns the size of each connected component. The canonical "DFS with return value" pattern asked at Google, Meta, and Amazon.
Capture every region of Os surrounded by Xs by inverting the problem — flood from the boundary instead of the interior. The classic boundary-DFS pattern interviewers love.
Compute the minimum minutes for rot to spread across a grid using multi-source BFS. The canonical "all sources start at the same time" pattern that solves dozens of grid-spreading problems.
For each cell, return the distance to the nearest 0. Multi-source BFS from every 0 simultaneously gives the answer in linear time — the gold-standard pattern asked at every FAANG company.
Flip at most one 0 to 1 to maximize island area. The "color the islands, then try every flip" trick avoids quadratic re-DFS — a top Google interview problem.
Find every cell from which water can flow to both oceans by reversing the flow and running DFS inward from each ocean. The reverse-flow trick that turns an O(N^4) brute force into O(N^2).
Find the shortest clear path from top-left to bottom-right in a binary grid with 8-directional movement. Pure BFS on an unweighted graph — the classic shortest-path-in-a-grid interview problem.
Find the water cell whose distance to the nearest land is maximized. Multi-source BFS from all land cells gives the answer in linear time — a top FAANG distance-spread problem.
Determine whether a word can be spelled by traversing adjacent cells without reusing any cell. The canonical DFS-with-backtracking template every grid-search interview problem builds on.
Process land additions one at a time and report the island count after each. Union-Find makes each query nearly O(1) amortized — the canonical online connectivity interview problem.
Master Clone Graph (LeetCode 133): a FAANG favorite that tests BFS, DFS, graph traversal, hash map state, and cycle handling. We trace it step by step, derive the optimal pattern, and fortify you against the classic mistakes interviewers love to spot.
LeetCode 547 Number of Provinces is the canonical connected-components question. Learn the DFS, BFS, and Union Find solutions, master the adjacency-matrix walk, and rehearse the FAANG interview script.
Classic graph reachability problem disguised as a puzzle. Treat each room as a node and each key as a directed edge, then run BFS or DFS from room 0 to check if every room can be visited.
A reachability check between two vertices in an undirected graph. Three optimal approaches: BFS, DFS, and Union Find — each with different trade-offs for follow-up questions about dynamic edges.
An array problem masquerading as a jump puzzle. Each index is a node with two outgoing edges (i + arr[i] and i - arr[i]), and the question reduces to a textbook BFS or DFS reachability check.
A directed graph cycle-detection problem solved by Kahn topological sort (BFS) or three-color DFS. The bedrock template behind dependency resolution at Maven, npm, Bazel, Make, and every modern build system.
The natural sequel to LC 207. Instead of asking whether you can finish all courses, this problem asks for a valid course ordering. Kahn algorithm gives the answer almost for free.
A graph is a valid tree iff it is connected and has no cycles, equivalently exactly n - 1 edges and one connected component. Solve with BFS, DFS, or Union Find — Union Find is shortest.
Count connected components by Union Find (decrement count on each successful union) or by BFS / DFS (increment count for each unvisited node). Both run in near-linear time.
Find the edge that closes a cycle when added to an n-node, n-edge graph. The first edge whose two endpoints share a Union Find root is the answer — a five-line solve.
LeetCode 126 Word Ladder II asks for every shortest transformation path between two words. Master the layered BFS plus parent-map DFS pattern that survives the brutal time limits at Amazon, Google, and Facebook interviews.
LeetCode 815 Bus Routes is deceptively hard. The trick is that BFS levels count buses, not stops, so the graph you traverse is a route graph. Master the stop-to-routes inversion that beats the time limit at FAANG interviews.
LeetCode 886 Possible Bipartition reduces a real-world group split to a bipartite check. Master the BFS 2-coloring, DFS coloring, and Union Find variants that recruiters expect at FAANG.
LeetCode 785 Is Graph Bipartite asks whether you can 2-color a graph. Master the BFS and DFS coloring patterns, the disconnected-component handling, and the FAANG interview script that proves you understand bipartite theory.
LeetCode 1654 Minimum Jumps to Reach Home looks like a number line puzzle, but it is a graph traversal in disguise. Master the state space BFS where direction is part of the node identity, plus the upper-bound trick that beats the time limit.
LeetCode 399 Evaluate Division turns equations like A/B equals 2 into a weighted graph. Master the BFS, DFS, and Union Find solutions plus the FAANG-grade interview script.
LeetCode 882 Reachable Nodes in Subdivided Graph blends Dijkstra with an edge-budget counting trick. Master the optimal pattern that interviewers at Google and Amazon use to filter senior candidates.