Intermediate Graph Theory Problems for Coding Interviews
80 intermediate Graph Theory problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 80 intermediate and 0 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
- Shortest Route in Weighted Graph (Intermediate)
- Shortest Path With One Free Edge (Intermediate)
- 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 Cost to Connect Network (Intermediate)
- Maximum Score Path in a DAG (Intermediate)
- Shortest Path In Binary Grid (Intermediate)
- Is Bipartite (Intermediate)
- Has Undirected Cycle (Intermediate)
- Minimum Cost to Reach Destination With Fuel (Intermediate)
- Count Perfect Matchings (Intermediate)
- Minimum Bisection Small Graph (Intermediate)
- Shortest Path With Limited Color Changes (Intermediate)
- Minimum Edge Weight to Connect Components (Intermediate)
- Minimum Cost to Reach Target With Coupons (Intermediate)
- PageRank Iteration (Intermediate)
- Minimum Cost Maximum Flow (Intermediate)
- Longest Univalue Path (Intermediate)
- Longest ZigZag Path in a Binary Tree (Intermediate)
- Maximum Product of Split Binary Tree (Intermediate)
- Good Leaf Node Pairs (Intermediate)
- Directions Between Two Tree Nodes (Intermediate)
- 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)
- Strongly Connected Components Count (Intermediate)
- Detonate the Maximum Bombs (Intermediate)
- Count Paths in a DAG (Intermediate)
- Unique Topological Order Check (Intermediate)
- Count Unreachable Pairs (Intermediate)
- Negative Cycle Detection (Intermediate)
- Minimum Score Polygon Triangulation (Intermediate)
- Equal Tree Partition (Intermediate)
- Closest Leaf to a Target (Intermediate)
- Count Nodes With the Highest Score (Intermediate)
- Eulerian Path Exists (Intermediate)
- Count Triangles in a Graph (Intermediate)
- Graph Diameter (Intermediate)
- Sum of All-Pairs Shortest Paths (Intermediate)
- Coloring a Border (Intermediate)
- Maximum Star Sum of a Graph (Intermediate)
- Closest Node to Two Nodes (Intermediate)
- Longest Cycle in a Functional Graph (Intermediate)
- Most Profitable Path in a Tree (Intermediate)
- Maximum Score After Tree Operations (Intermediate)
- Minimum Time to Visit Disappearing Nodes (Intermediate)
- Maximum K-Divisible Components (Intermediate)
- Longest Path in DAG Between Two Nodes (Intermediate)
- Largest Component Size After Each Edge (Intermediate)
- Graph Radius (Intermediate)
- Shortest Round Trip From Node One (Intermediate)
- Distance to Nearest Marked Node (Intermediate)
- Farthest Pair Distance in Connected Graph (Intermediate)
- Nodes on Some Shortest Path (Intermediate)
- Maximum Matching in a Tree (Intermediate)
- Maximum Independent Set Size in Tree (Intermediate)
- Maximum Edges Cut So Components Divisible by K (Intermediate)
- Coin Redistribution Moves on Tree (Intermediate)
- DAG Token Game Winner (Intermediate)
- Expected Isolated Nodes in Random Graph (Intermediate)
- Boundary Lattice Points of Polygon (Intermediate)
- Interior Lattice Points of Polygon (Intermediate)
- Is Polygon Convex (Intermediate)
- Number of Corner Points of Convex Hull (Intermediate)
- Maximum Layer Sum of Matrix (Intermediate)
- Count Labeled Graphs on N Nodes (Intermediate)
- Edges Needed to Connect Graph (Intermediate)
- Triangle Count (Intermediate)
- Vertices at Distance Two (Intermediate)
- Eulerian Circuit Exists (Intermediate)
- Sum of Distances From Vertex Zero (Intermediate)
- Farthest Reachable Distance (Intermediate)
- Independent Cycle Count (Intermediate)
- Right Triangle Triples (Intermediate)
Related
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.