Model things as nodes and edges, then traverse: components, shortest paths, cycles, ordering, and coloring.
Group nodes that can reach each other.
O(V + E)When to reach for it
Spot it in the prompt
Look for problems where you need to group nodes based on their connectivity, often involving DFS or BFS traversal.
How to solve it
Scan the grid and launch DFS or BFS from each unvisited land cell, marking the whole island; count how many launches occur.
Open full solutionReach a target with minimum total cost.
O((V + E) log V)When to reach for it
Spot it in the prompt
Look for problems where you need to optimize distance or traversal time between two points, typically using Dijkstra's or Floyd-Warshall algorithms.
How to solve it
Animation: Shortest Path Finding techniqueRun Dijkstra from the source over the weighted edges; the answer is the maximum settled distance, or -1 if any node is unreachable.
Open full solutionSpot when traversal loops back on itself.
O(V + E)When to reach for it
Spot it in the prompt
Look for problems where you need to ensure that no node is visited more than once during traversal, employing DFS or BFS to detect back edges.
How to solve it
Animation: Cycle Detection techniqueBuild the prerequisite graph and run Kahn's topological sort; if every course gets ordered there is no cycle, so the schedule is feasible.
Open full solutionTwo-color the graph without conflicts.
O(V + E)When to reach for it
Spot it in the prompt
Look for problems where you need to color nodes alternately while traversing the graph to detect any conflicts.
How to solve it
Animation: Bipartite Graph Check techniqueTraverse each component assigning alternating colors to neighbors; if an edge ever connects two same-colored nodes, the graph is not bipartite.
Open full solutionConnect everything for the least total weight.
O(E log E)When to reach for it
Spot it in the prompt
Look for problems involving weighted edges and the need to minimize the total weight to connect all nodes.
How to solve it
Animation: Minimum Spanning Tree techniqueBuild a minimum spanning tree over the complete graph of Manhattan distances using Prim's heap or Kruskal with union-find.
Open full solutionOrder or explore edges that never loop.
O(V + E)When to reach for it
Spot it in the prompt
Look for problems where you need to perform a topological sort or find the longest path without revisiting nodes.
How to solve it
Animation: Directed Acyclic Graph (DAG) Traversal techniqueDerive ordering edges from adjacent word pairs, then topologically sort the letters; a cycle or bad prefix means no valid order exists.
Open full solutionColor adjacent nodes differently.
When to reach for it
Spot it in the prompt
Look for problems where you need to color the graph with a minimum number of colors without violating the coloring rule.
How to solve it
Animation: Graph Coloring techniqueTwo-coloring is graph coloring with two colors: alternate colors along edges during traversal, and a same-color edge means it can't be done.
Open full solutionFDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI