Topic
Graph interview questions
All 48 Graph problems from the curated set, easiest first — a core topic for 11 of the 29 engineering roles.
- Easy
- 1
- Medium
- 36
- Hard
- 11
- Sheets
- 3
What Graph is
Updated 2026-09-09A graph is a network of individual points, called vertices or nodes, connected by lines called edges. Think of a subway transit map, an electrical circuit, or a web of social friends. Unlike a tree, a graph has no designated top node and no parent-child hierarchy. Connections can run one-way or both ways, and paths can loop back on themselves to form closed cycles.
When to reach for it
Reach for graph algorithms when inputs describe relationships, networks, flights between cities, course prerequisites, or clone networks. Signals include finding the shortest route across unweighted connections, ordering tasks that depend on earlier tasks, counting isolated clusters, or checking whether a path contains an infinite loop. Whenever problems present pairs of related entities and ask for reachability, distances, or dependencies, graph representations apply.
How to think about it
First convert edge lists into an adjacency list, mapping each node to an array of its neighbors. Choose your exploration strategy based on the goal: use a queue and breadth-first search to find the shortest path in unweighted networks, or use recursion and depth-first search to explore full paths and detect cycles. Because graphs can have loops, always track visited nodes in a set or boolean array. Add nodes to the visited set at the moment they enter the queue so they are never visited twice.
What each operation costs
| Operation | Time |
|---|---|
| visit all nodes and edges via search | O(v + e) |
| topological sort using in-degree counts | O(v + e) |
| shortest path using dijkstra with a min-heap | O((v + e) log v) |
What usually goes wrong
- Adding a node to the visited set when popping from the queue instead of when pushing, which lets neighboring nodes enqueue duplicate entries and wastes memory.
- Failing to check for cycles in directed graphs when finding prerequisite orders, causing topological sort routines to hang or return incomplete lists.
- Assuming an input graph is fully connected and scanning from only a single starting node, missing disconnected islands and isolated components.
Every Graph problem, easiest first
- Flood FillEasy
- Number of IslandsMedium
- Clone GraphMedium
- Course ScheduleMedium
- Course Schedule IIMedium
- Pacific Atlantic Water FlowMedium
- Surrounded RegionsMedium
- Rotting OrangesMedium
- Walls and GatesMedium
- Redundant ConnectionMedium
- Number of Connected Components in Undirected GraphMedium
- Graph Valid TreeMedium
- Detect Cycle in Undirected GraphMedium
- Detect Cycle in Directed GraphMedium
- Topological Sort (DFS)Medium
- Topological Sort (BFS - Kahn's)Medium
- Dijkstra's AlgorithmMedium
- Bellman Ford AlgorithmMedium
- Floyd Warshall AlgorithmMedium
- Prim's Algorithm (MST)Medium
- Kruskal's Algorithm (MST)Medium
- Bipartite Graph CheckMedium
- Shortest Path in Unweighted GraphMedium
- Number of ProvincesMedium
- Requirements Met (Prerequisite Tasks)Medium
- Find Eventual Safe StatesMedium
- Network Delay TimeMedium
- Cheapest Flights Within K StopsMedium
- Path with Minimum EffortMedium
- Accounts MergeMedium
- Find the City with Fewest Reachable NeighboursMedium
- Kahn's Algorithm BFS Topological SortMedium
- Minimum Spanning Tree (Prim)Medium
- Shortest Path in DAGMedium
- Maximum Stone Removal (DSU)Medium
- Most Stones Removed with Same Row or ColumnMedium
- Count Unreachable Pairs of Nodes in Undirected GraphMedium
- Word LadderHard
- Alien DictionaryHard
- Swim in Rising WaterHard
- Making a Large IslandHard
- Strongly Connected Components (Kosaraju's)Hard
- Bridges in GraphHard
- Articulation Points in GraphHard
- Minimum Number of Days to Disconnect IslandHard
- Word Ladder IIHard
- Number of Islands II (DSU)Hard
- Maximum Connected Group (DSU)Hard
Roles that need Graph
If you are targeting one of these, Graph sits early in your path rather than being optional.
Track Graph in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks. Free.
Start freeGraph interview questions, answered
How many Graph problems should I solve for interviews?
48 curated Graph problems cover the patterns interviews repeat: 1 easy, 36 medium and 11 hard. They are drawn from 3 widely used sheets, deduplicated, and ordered easiest first.
Is Graph actually asked in coding interviews?
Yes, though how much depends on the role. Graph is a core topic for 11 of the 29 engineering roles tracked here, including SDE / Backend Engineer, Data Engineer, Game Developer. For other roles it is lower frequency and belongs later in a study plan.
Which Graph problem should I start with?
Start with Flood Fill (Easy). The list on this page is ordered easiest first for that reason, so working top to bottom builds the pattern before the harder variations arrive.
Other topics
Problem set and role mapping as of .