Graph Theory Problems for Coding Interviews
188 Graph Theory problems from real coding interviews, each with test cases you can run online. By difficulty they split into 34 basic, 80 intermediate and 74 advanced. The companies that ask them most often are Google, Amazon, 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
- Skyline Key Points (Basic)
- Shortest Route in Weighted Graph (Intermediate)
- Count Islands With Diagonal Adjacency (Advanced)
- Shortest Path With One Free Edge (Intermediate)
- Count Shortest Paths (Advanced)
- Maximum Flow Network (Advanced)
- Minimum Height Trees (Intermediate)
- Shortest Path With Alternating Colours (Intermediate)
- Count Complete Components (Intermediate)
- Minimum Edge Reversals Per Node (Intermediate)
- Count Walks With Exact Length (Intermediate)
- Minimum Path Cover in a DAG (Advanced)
- Maximum Weight Cut (Basic)
- Minimum Cost to Connect Network (Intermediate)
- Shortest Cycle in Undirected Graph (Advanced)
- Maximum Score Path in a DAG (Intermediate)
- Tree Nodes at Distance K (Advanced)
- Tree Distance Queries (Basic)
- Tree Diameter (Advanced)
- Shortest Path In Binary Grid (Intermediate)
- Number of Connected Components (Basic)
- Is Bipartite (Intermediate)
- Has Undirected Cycle (Intermediate)
- Network Delay Time (Advanced)
- Minimum Number of Reflections (Advanced)
- Minimum Cost to Reach Destination With Fuel (Intermediate)
- Shortest Path Through Maze Keys and Doors (Advanced)
- Count Perfect Matchings (Intermediate)
- Minimum Bisection Small Graph (Intermediate)
- Shortest Path With Limited Color Changes (Intermediate)
- N-ary Tree Diameter (Advanced)
- Minimum Edge Weight to Connect Components (Intermediate)
- Find All Ancestors in DAG (Basic)
- Minimum Cost to Reach Target With Coupons (Intermediate)
- Maximum Path Quality (Basic)
- PageRank Iteration (Intermediate)
- Maximum Flow With Lower Bounds (Basic)
- Minimum Cost Maximum Flow (Intermediate)
- Steiner Tree Small Graph (Basic)
- Binary Tree Maximum Path Sum (Advanced)
- Longest Univalue Path (Intermediate)
- Insert GCDs Between Adjacent Nodes (Basic)
- Minimum Depth of Binary Tree (Basic)
- Longest ZigZag Path in a Binary Tree (Intermediate)
- Maximum Product of Split Binary Tree (Intermediate)
- Tree Height After Subtree Removal Queries (Advanced)
- Good Leaf Node Pairs (Intermediate)
- Directions Between Two Tree Nodes (Intermediate)
- Sum of Distances in Tree (Advanced)
- Count Same-Label Nodes in Subtrees (Intermediate)
- Minimum Time to Collect All Apples (Intermediate)
- Graph Valid Tree (Intermediate)
- Pacific Atlantic Water Flow (Intermediate)
- Redundant Connection (Intermediate)
- Eventual Safe States (Intermediate)
- Bridges in a Graph (Advanced)
- Articulation Points (Advanced)
- Strongly Connected Components Count (Intermediate)
- Detonate the Maximum Bombs (Intermediate)
- Count Paths in a DAG (Intermediate)
- Unique Topological Order Check (Intermediate)
- Shortest Path Visiting All Nodes (Advanced)
- Reachable Nodes in Subdivided Graph (Advanced)
- Second Minimum Arrival Time (Advanced)
- Count Unreachable Pairs (Intermediate)
- Largest Color Value in a Directed Graph (Advanced)
- Critical and Pseudo-Critical MST Edges (Advanced)
- Negative Cycle Detection (Intermediate)
- Number of Restricted Paths (Advanced)
- Immediate Dominators (Advanced)
- Minimum Vertices to Reach All Nodes (Basic)
- Minimum Edges to Make Graph Strongly Connected (Advanced)
- Minimum Vertex Cut (Advanced)
- Minimum Score Polygon Triangulation (Intermediate)
- Convex Hull Vertex Count (Advanced)
- Point in Polygon Classification (Advanced)
- Equal Tree Partition (Intermediate)
- Closest Leaf to a Target (Intermediate)
- Count Nodes With the Highest Score (Intermediate)
- Find Center of Star Graph (Basic)
Related
- Basic Graph Theory problems
- Intermediate Graph Theory problems
- Advanced Graph Theory problems
- Practice coding problems online
- All interview guides
Frequently asked questions
How do I get good at graph theory 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 graph theory 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.