Skip to main content
Back to Topics

Graph Problems (190)

Problems tagged with Graph

About Graph

A Graph is one of the most powerful and widely used data structures in computer science. A graph consists of nodes (vertices) connected by edges, representing relationships between entities. Graphs can model real-world systems such as social networks, road maps, computer networks, recommendation systems, and dependency pipelines. Because of their flexibility, graph problems frequently appear in technical interviews at companies like Google, Amazon, and Meta.

In coding interviews, graph questions test your ability to model complex relationships and traverse structures efficiently. Many well-known interview problems involve identifying connected components, detecting cycles, finding the shortest path, or determining ordering constraints. To solve these problems, developers rely on foundational traversal algorithms like Breadth-First Search and Depth-First Search, which allow you to explore nodes layer by layer or recursively.

Beyond basic traversal, graph problems often combine multiple algorithmic techniques. For example, connectivity problems frequently use the Union Find data structure, while dependency resolution problems rely on Topological Sort. Route optimization and weighted graphs commonly require algorithms from the Shortest Path family such as Dijkstra’s or Bellman-Ford.

Common graph patterns you will encounter include:

  • Graph traversal using BFS or DFS
  • Cycle detection in directed or undirected graphs
  • Connected components and island-style problems
  • Shortest path and weighted graph algorithms
  • Graph coloring and bipartite checks

You should use graph algorithms whenever a problem involves relationships, networks, dependencies, or paths between entities. If the input can be modeled as nodes connected by edges—such as cities, users, tasks, or states—it is often a graph problem in disguise.

FleetCode provides 181 carefully curated Graph practice problems designed to help you recognize patterns, implement algorithms efficiently, and build the intuition needed to solve real interview questions. By mastering graph fundamentals and practicing diverse problem types, you can confidently tackle some of the most challenging questions in coding interviews.

Prerequisites

1
Union Find

Union Find (Disjoint Set Union) is commonly used in graph problems involving connectivity, component merging, and detecting cycles in undirected graphs.

2
Shortest Path

Shortest path algorithms like Dijkstra and Bellman-Ford are used to compute minimum distances in weighted graphs and appear frequently in advanced graph interview questions.

3
Topological Sort

Topological sorting is critical for solving dependency and ordering problems in directed acyclic graphs, such as course scheduling or task pipelines.

4
Depth-First Search

DFS helps explore graphs recursively and is essential for cycle detection, connected components, and backtracking-based graph problems.

5
Breadth-First Search

BFS is a core graph traversal technique used to explore nodes level by level. It forms the basis for solving shortest path problems in unweighted graphs and many grid or island problems.

#1615

Maximal Network Rank

Medium✓ Solution📹 Video
Microsoft
Page 1 of 2

Practice by Difficulty

Start Easy, progress to Hard.

FAQ

Common questions about Graph.

Is Graph an important topic for FAANG interviews?

Yes, graph algorithms are extremely important for FAANG and top tech interviews. Many medium and hard interview questions involve graphs, including dependency resolution, network traversal, and pathfinding. Mastery of BFS, DFS, and shortest path algorithms is often expected.

What are the common patterns in Graph DSA problems?

The most common graph patterns include BFS/DFS traversal, cycle detection, connected components, bipartite graph checks, topological ordering, and shortest path algorithms. Many problems combine these techniques with data structures like heaps or Union Find.

How do you identify a Graph problem in coding interviews?

A problem is likely a graph problem if it involves relationships, networks, dependencies, routes, or transformations between states. If elements are connected and you need to explore paths or components between them, modeling the problem as a graph is often the right approach.

How many Graph problems should I solve to master the topic?

Most candidates reach strong proficiency after solving around 60–120 graph problems covering traversal, shortest paths, topological sorting, and connectivity. FleetCode provides 181 graph problems so you can progress from beginner concepts to advanced interview-level challenges.

What are the most common Graph problems in coding interviews?

Common graph interview problems include number of islands, course schedule, clone graph, network delay time, and shortest path in a grid. These typically involve BFS, DFS, Union Find, or shortest path algorithms. Practicing 50–100 graph problems usually exposes you to most interview patterns.

What is the best way to learn Graph algorithms for coding interviews?

Start by learning graph representations (adjacency list or matrix), then master BFS and DFS traversal. After that, practice patterns like cycle detection, connected components, topological sorting, and shortest path algorithms. Consistent problem practice is key to recognizing graph patterns quickly.