All topics
7 patterns · 34 problems

Graphs

Model things as nodes and edges, then traverse: components, shortest paths, cycles, ordering, and coloring.

01Pattern

Finding Connected Components

Group nodes that can reach each other.

This patternO(V + E)

When to reach for it

  • You're given a graph, and you need to identify distinct subgraphs where all vertices are connected to each other by paths.

Spot it in the prompt

Look for problems where you need to group nodes based on their connectivity, often involving DFS or BFS traversal.

Medium Bespoke animation

Number of Islands

LeetCode
Loading animation…

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 solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

02Pattern

Shortest Path Finding

Reach a target with minimum total cost.

This patternO((V + E) log V)

When to reach for it

  • Given a graph with weighted edges, you're tasked with finding the shortest path between two nodes.

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.

Medium

Network Delay Time

LeetCode
Loading animation…

How to solve it

Animation: Shortest Path Finding technique

Run Dijkstra from the source over the weighted edges; the answer is the maximum settled distance, or -1 if any node is unreachable.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

03Pattern

Cycle Detection

Spot when traversal loops back on itself.

This patternO(V + E)

When to reach for it

  • You're required to detect whether a graph contains cycles or not.

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.

Medium

Course Schedule

LeetCode
Loading animation…

How to solve it

Animation: Cycle Detection technique

Build 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 solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

04Pattern

Bipartite Graph Check

Two-color the graph without conflicts.

This patternO(V + E)

When to reach for it

  • You need to determine if a given undirected graph is bipartite, i.e., it's possible to split the vertices into two independent sets such that no edge connects vertices of the same set.

Spot it in the prompt

Look for problems where you need to color nodes alternately while traversing the graph to detect any conflicts.

Medium

Is Graph Bipartite?

LeetCode
Loading animation…

How to solve it

Animation: Bipartite Graph Check technique

Traverse each component assigning alternating colors to neighbors; if an edge ever connects two same-colored nodes, the graph is not bipartite.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

05Pattern

Minimum Spanning Tree

Connect everything for the least total weight.

This patternO(E log E)

When to reach for it

  • You're tasked with finding the minimum weight connected subtree that connects all vertices in a graph.

Spot it in the prompt

Look for problems involving weighted edges and the need to minimize the total weight to connect all nodes.

Medium

Min Cost to Connect All Points

LeetCode
Loading animation…

How to solve it

Animation: Minimum Spanning Tree technique

Build a minimum spanning tree over the complete graph of Manhattan distances using Prim's heap or Kruskal with union-find.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

06Pattern

Directed Acyclic Graph (DAG) Traversal

Order or explore edges that never loop.

This patternO(V + E)

When to reach for it

  • You're given a directed graph without cycles, and you need to traverse it efficiently.

Spot it in the prompt

Look for problems where you need to perform a topological sort or find the longest path without revisiting nodes.

Hard

Alien Dictionary

LeetCode
Loading animation…

How to solve it

Animation: Directed Acyclic Graph (DAG) Traversal technique

Derive ordering edges from adjacent word pairs, then topologically sort the letters; a cycle or bad prefix means no valid order exists.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

07Pattern

Graph Coloring

Color adjacent nodes differently.

When to reach for it

  • You need to assign colors to the vertices of a graph such that no two adjacent vertices have the same color.

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.

Medium

Is Graph Bipartite?

LeetCode
Loading animation…

How to solve it

Animation: Graph Coloring technique

Two-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 solution

Practice · 4 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE 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

August 15 · 0d left
Enroll Now