Depth-First Search Problems for Coding Interviews
32 Depth-First Search problems from real coding interviews, each with test cases you can run online. By difficulty they split into 9 basic, 13 intermediate and 10 advanced. The companies that ask them most often are Amazon, Google, Microsoft, Meta.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Largest Island After One Flip (Intermediate)
- Count Islands With Diagonal Adjacency (Advanced)
- Count Complete Components (Intermediate)
- Shortest Cycle in Undirected Graph (Advanced)
- Shortest Bridge Between Two Islands (Intermediate)
- Minimum Path Sum (Intermediate)
- Flood Fill Region Size (Basic)
- Number of Connected Components (Basic)
- Dynamic Island Additions (Advanced)
- Count Distinct Islands Shapes (Basic)
- Binary Tree Maximum Path Sum (Advanced)
- Binary Tree Paths (Basic)
- Number of Islands (Basic)
- Bridges in a Graph (Advanced)
- Articulation Points (Advanced)
- Strongly Connected Components Count (Intermediate)
- Count Sub Islands (Intermediate)
- Largest Color Value in a Directed Graph (Advanced)
- Island Perimeter (Basic)
- Number of Closed Islands (Intermediate)
- Minimum Falling Path Sum (Intermediate)
- Number of Increasing Paths in a Grid (Advanced)
- Has Root-to-Leaf Path Sum (Basic)
- Minimum Root-to-Leaf Path Sum (Basic)
- Maximum Path Sum Between Two Leaves (Advanced)
- Minimum Days to Disconnect Island (Advanced)
- Longest Cycle in a Functional Graph (Intermediate)
- Minimum Path Sum With One Skip (Intermediate)
- Minimum Falling Path Sum With Diagonal Penalty (Intermediate)
- Maximum Edges Cut So Components Divisible by K (Intermediate)
- Component Count After Each Edge (Basic)
- Independent Cycle Count (Intermediate)
Related
- Basic Depth-First Search problems
- Intermediate Depth-First Search problems
- Advanced Depth-First Search problems
- Practice coding problems online
- All interview guides
Frequently asked questions
How do I get good at depth-first search problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run depth-first search problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.