Master Prim's algorithm for Minimum Spanning Tree: grow a single tree from any starting vertex by repeatedly attaching the cheapest crossing edge using a min-heap. The dense-graph counterpart to Kruskal, asked at Google, Amazon, and Microsoft.
Master Tarjan's SCC algorithm: a single DFS pass with discovery times, low-link values, and an explicit stack to identify all strongly connected components in O(V + E). The interview gold standard for directed graph decomposition, asked at Google, Meta, and Uber.
Use Tarjan's low-link technique to find every bridge (critical edge) and articulation point (cut vertex) in an undirected graph in O(V + E). The interview pattern behind LeetCode 1192 Critical Connections, asked at Google, Meta, and Amazon.
Master the Floyd-Warshall algorithm: a triple-nested DP that computes shortest paths between every pair of vertices in O(V^3), supports negative edges, and detects negative cycles. The interview workhorse for dense graphs and small V, asked at Google, Amazon, and Microsoft.
Master Bellman-Ford: relax every edge V-1 times to compute single-source shortest paths even with negative edges, and detect negative cycles in one extra pass. The algorithm behind LeetCode 787 Cheapest Flights Within K Stops, asked at Google, Amazon, and Meta.
Master A* search: a heuristic-guided best-first search that finds optimal shortest paths far faster than Dijkstra by combining actual distance g(n) with an admissible estimate h(n). The interview pattern behind LeetCode 1091 Shortest Path in Binary Matrix and the algorithm powering Google Maps, game AI, and robotics navigation.
Master advanced Dijkstra: state augmentation, K-stop limits, two-cost optimisation, k-th shortest paths, and modified relaxation. The interview pattern behind LeetCode 787, 1928, and 1976, asked at Google, Amazon, and Meta.
Master bipartite checking and graph coloring: a single BFS or DFS pass that 2-colors a graph and proves it is bipartite, or finds an odd cycle. The pattern behind LeetCode 785 Is Graph Bipartite and LeetCode 886 Possible Bipartition, asked at Google, Meta, and Amazon.
Master LeetCode 1584 Min Cost to Connect All Points: model the n^2 implicit edges as a complete graph, then run Prim's MST in O(n^2) without ever materialising the edge list. A FAANG-favourite interview question at Amazon, Google, and Meta that tests whether you can spot a Minimum Spanning Tree behind a geometry prompt.
Solve the bottleneck shortest path problem: find a route from source to destination that minimises the maximum edge weight on the path. Combines binary search on the answer with BFS connectivity checks in O((V+E) log W) — a FAANG interview pattern asked at Google and Amazon, and the foundation behind LeetCode 1102 Path With Maximum Minimum Value.
Master LeetCode 1976 Number of Ways to Arrive at Destination: extend Dijkstra to count the number of distinct shortest paths simultaneously, returning the count modulo 10^9+7. A FAANG-favourite shortest-path counting interview question asked at Google, Amazon, and Meta.
Master LeetCode 1192 Critical Connections in a Network: a textbook Tarjan bridge-finding algorithm using DFS with discovery times and low-link values to detect every edge whose removal disconnects the graph. A FAANG hard graph interview classic at Google, Amazon, and Meta.
Master LeetCode 332 Reconstruct Itinerary using Hierholzer's algorithm: a single DFS that traverses every edge exactly once and assembles an Eulerian path via post-order insertion. A FAANG hard interview classic asked at Google, Meta, and Amazon, and the foundational pattern for de Bruijn sequences and DNA fragment assembly.
Master LeetCode 778 Swim in Rising Water by reducing a grid puzzle to a minimax shortest-path problem. Solve it three ways — Dijkstra with max-relax, binary search plus BFS, and Kruskal-style union-find — and learn when each approach wins. A FAANG hard interview classic at Google, Amazon, and Meta.
Master longest path in a directed acyclic graph (DAG): a polynomial-time graph-DP that combines topological sort with memoised DFS. The same template solves LeetCode 329 Longest Increasing Path, course planning with prerequisites, and critical-path scheduling — a FAANG interview pattern at Google, Amazon, and Meta.
A complete walkthrough of network flow for FAANG interviews: the max-flow min-cut theorem, Ford-Fulkerson, Edmonds-Karp BFS-augmenting paths, residual graphs, and practical applications including bipartite matching and project selection. Asked at Google, Amazon, and Meta as a senior-level systems-design-meets-algorithms screen.
Master BFS and DFS on graphs and grids with the seven core patterns that show up in 90 percent of FAANG graph interviews. Learn flood fill, multi-source BFS, shortest path on unweighted graphs, and connected components with Python and JavaScript code.
Solve LeetCode 200 Number of Islands with DFS flood fill in O(m*n) time. The most asked grid traversal problem at Amazon, Google, and Meta — covers DFS, BFS, and Union-Find approaches with Python and JavaScript.
Solve LeetCode 733 Flood Fill with simple DFS in O(m*n) time. The paint bucket tool from MS Paint reduced to a five-line recursion — the cleanest introduction to grid traversal you can give an interviewer.
Solve LeetCode 463 Island Perimeter in O(m*n) without DFS or BFS. The trick: every land cell contributes 4 edges, minus 2 for each shared edge with another land cell. Pure counting beats traversal.
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.
LC 286 Walls and Gates asks you to fill each empty room with its distance to the nearest gate. The key insight is to flip the direction: instead of BFS from every room, do multi-source BFS from all gates simultaneously and push distances outward in O(m*n) time.
LC 1020 Number of Enclaves asks you to count land cells that cannot reach the grid boundary. The trick is to flip the problem: flood-fill from the boundary inward, eliminating all reachable land, then count what remains.
LC 1905 Count Sub Islands asks how many islands in grid2 are subsets of islands in grid1. The critical trap is short-circuiting DFS on the first invalid cell — you must always complete the traversal to mark the whole island visited, while tracking validity separately.
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.
Count islands with unique shapes by encoding each DFS traversal path as a string and storing shapes in a set. A classic interview problem testing DFS + hashing.
Count land islands fully surrounded by water (no border touch). Flood-fill border land first to eliminate open islands, then count remaining closed components.
Find the minimum number of 0s to flip to connect two islands. Use DFS to color the first island, then multi-source BFS to expand outward until hitting the second island.
Find the path from top-left to bottom-right that minimizes the maximum absolute difference between consecutive cells. Dijkstra treats effort as edge weight; binary search + BFS checks feasibility for each candidate effort.
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.
BFS from the entrance to find the nearest border empty cell that is not the entrance. Classic BFS shortest-path on a grid with a carefully defined exit condition.
Minimum dice rolls to reach square n² from square 1. The hard part is converting square numbers to board coordinates in Boustrophedon (snake) order. BFS on the state space of squares gives the optimal answer.
Find the minimum number of turns to go from "0000" to the target combination on a 4-wheel lock, avoiding deadend states. Classic BFS on a finite state space — the lock combination is the node, each wheel turn is an edge.
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.
LC 743 Network Delay Time asks for the time a signal takes to reach all n nodes from source k. Single-source shortest path via Dijkstra gives every distance in O(E log V); the answer is the maximum among them.
LC 787 Cheapest Flights Within K Stops asks for the cheapest route from src to dst using at most k intermediate stops. Bellman-Ford with exactly k+1 relaxation rounds handles the stop constraint cleanly without Dijkstra getting confused by the layered state.
LC 127 Word Ladder asks for the shortest sequence of one-letter transformations from beginWord to endWord, where every intermediate word must be in the dictionary. BFS on the implicit word-state graph finds the minimum in O(M^2 * N) using wildcard pattern grouping.
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.
Week 2 of the FAANG mock program pairs Number of Islands and Longest Increasing Subsequence. Solve each correctly, then deliver one optimization upgrade and handle a live follow-up question — the pattern that separates "passes" from "strong hire" ratings.
Build GraphRAG systems using knowledge graph traversal and vector search together to handle complex multi-hop questions and relationship-aware context retrieval.