Blind 75 Graph Questions
7 problems · Free practice
Graph problems often hide their nodes and edges inside another story: a grid, prerequisites, or relationships between words. First identify that graph, then decide whether the task is reachability, connectivity, cloning, or ordering. Directed and undirected edges require different cycle-detection reasoning.
Practice graphs
Number of Islands
MediumCount connected groups of land in a rectangular grid of 0s and 1s. Land connects horizontally or vertically, never diagonally.
Clone Graph
MediumDeep-copy the connected component reachable from a graph node. Each node has a value and a list of neighboring nodes; cycles may occur. Return null for a null input.
Pacific Atlantic Water Flow
MediumIn a rectangular height grid, water may move to a horizontal or vertical neighbor of equal or lower height. Return cells that can reach both the top/left boundary and the bottom/right boundary.
Course Schedule
MediumThere are n courses labeled 0 through n−1. Each pair [a, b] requires taking b before a. Decide whether all courses can be completed.
Graph Valid Tree
MediumGiven n ≥ 1 vertices labeled 0 through n−1 and undirected edges without self-loops or duplicate edges, decide whether the graph is one tree.
Number of Connected Components in an Undirected Graph
MediumCount connected components among n vertices labeled 0 through n−1, including isolated vertices, given a list of undirected edges.
Alien Dictionary
HardGiven nonempty words sorted under an unknown character order, return any ordering of all observed characters consistent with that sort. Return an empty string if no valid ordering exists.
What to focus on
- Define the nodes and edges before choosing BFS, DFS, or another method.
- Mark nodes at a deliberate point so repeated edges do not create repeated work.
- Include disconnected components and cycles in your examples.