Graphs
Nodes and edges modeling networks, dependencies, and paths.
Graphs Practice Problems
Easy
4 problems- 440easy
Find Center of Star Graph
Spot the middle node of a star-shaped graph by comparing only the first two edges, with no counting and no traversal.
- 441easy
Find the Town Judge
Give every person one score built from who trusts whom, then read off the only person who trusts nobody and is trusted by all.
- 442easy
Keys and Rooms
Use a stack to open rooms with the keys you collect, and decide whether every room can be reached from room 0.
- 443easy
Max Area of Island
Treat a grid of ones and zeros as a graph and flood fill each island, sinking cells as you count, to find the largest one.
Medium
4 problems- 444medium
Clone Graph
Make a deep copy of a graph that contains cycles by keeping a map from each original node to the single copy that stands for it.
- 445medium
Is Graph Bipartite
Paint the graph in two colours with a breadth-first walk and decide whether the nodes split into two groups with no edge inside a group.
- 446medium
All Paths From Source to Target
List every route from the first node to the last in a directed graph with no cycles, using backtracking to undo one move at a time.
- 447medium
Minimum Number of Vertices to Reach All Nodes
Find the smallest set of starting nodes that reaches everything by collecting exactly the nodes with no arrow pointing at them.
Hard
2 problems- 448hard
Critical Connections in a Network
Find every bridge in a network using discovery times and low-link values from a single depth-first walk.
- 449hard
Reconstruct Itinerary
Order a pile of airline tickets into one trip from JFK that uses every ticket once, picking the alphabetically smallest valid route.
Related concepts
| Topic | Description |
|---|---|
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |
| Breadth-First Search | Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph. |
| Arrays | Ordered indexable collection for O(1) access by position. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Stacks | Last-in, first-out collection for undo, parsing, and nested work. |
| Queues | First-in, first-out collection for scheduling, BFS, and buffering. |