Advanced Graph Theory Problems for Coding Interviews
74 advanced Graph Theory problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 0 intermediate and 74 advanced. The companies that ask them most often are Google, Amazon, Meta, Microsoft.
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
- Count Islands With Diagonal Adjacency (Advanced)
- Count Shortest Paths (Advanced)
- Maximum Flow Network (Advanced)
- Minimum Path Cover in a DAG (Advanced)
- Shortest Cycle in Undirected Graph (Advanced)
- Tree Nodes at Distance K (Advanced)
- Tree Diameter (Advanced)
- Network Delay Time (Advanced)
- Minimum Number of Reflections (Advanced)
- Shortest Path Through Maze Keys and Doors (Advanced)
- N-ary Tree Diameter (Advanced)
- Binary Tree Maximum Path Sum (Advanced)
- Tree Height After Subtree Removal Queries (Advanced)
- Sum of Distances in Tree (Advanced)
- Bridges in a Graph (Advanced)
- Articulation Points (Advanced)
- Shortest Path Visiting All Nodes (Advanced)
- Reachable Nodes in Subdivided Graph (Advanced)
- Second Minimum Arrival Time (Advanced)
- Largest Color Value in a Directed Graph (Advanced)
- Critical and Pseudo-Critical MST Edges (Advanced)
- Number of Restricted Paths (Advanced)
- Immediate Dominators (Advanced)
- Minimum Edges to Make Graph Strongly Connected (Advanced)
- Minimum Vertex Cut (Advanced)
- Convex Hull Vertex Count (Advanced)
- Point in Polygon Classification (Advanced)
- Minimum Weighted Subgraph With Required Paths (Advanced)
- Redundant Directed Connection (Advanced)
- Count Proper K-Colorings (Advanced)
- Hamiltonian Path Exists (Advanced)
- Maximum Clique Size (Advanced)
- Maximum Independent Set in a Small Graph (Advanced)
- Shortest Paths With Negative Edges (Advanced)
- Kth Shortest Path Length (Advanced)
- Second Best Minimum Spanning Tree (Advanced)
- Count Spanning Trees (Advanced)
- Number of Good Paths (Advanced)
- Count Pairs of Nodes by Degree (Advanced)
- Minimum Degree of a Connected Trio (Advanced)
- Collect Coins in a Tree (Advanced)
- Count Possible Root Nodes (Advanced)
- Max Min Price Sum Difference (Advanced)
- Count Prime Paths in a Tree (Advanced)
- Minimum AND Cost Walk (Advanced)
- Count Visited Nodes in a Functional Graph (Advanced)
- Graph Connectivity With Threshold (Advanced)
- Edge Length Limited Paths (Advanced)
- Remove Max Edges Keeping Full Traversal (Advanced)
- Minimize Malware Spread (Advanced)
- Minimize Malware Spread II (Advanced)
- Tree of Coprimes (Advanced)
- Create Components With Same Value (Advanced)
- Cat and Mouse (Advanced)
- Trapping Rain Water II (Advanced)
- Cheapest Route With One Half-Price Flight (Advanced)
- Number of Cheapest Routes (Advanced)
- K-th Successor in Functional Graph (Advanced)
- Count Hamiltonian Paths From First to Last (Advanced)
- Fewest Edge Flips to Connect Two Nodes (Advanced)
- Graphical Degree Sequence Check (Advanced)
- Number of Closed Walks of Length K (Advanced)
- Paths of Exactly K Edges Between Two Nodes (Advanced)
- Strictly Longer Second Route Length (Advanced)
- Farthest Node Distance for Every Node (Advanced)
- Prufer Sequence of Labeled Tree (Advanced)
- Edges From Prufer Sequence (Advanced)
- Green Hackenbush Tree Winner (Advanced)
- Is Polygon Simple (Advanced)
- Chromatic Number of Small Graph (Advanced)
- Minimum Dominating Set of Small Graph (Advanced)
- Hamiltonian Cycle Exists in Small Graph (Advanced)
- Maximum Weight Matching in Small General Graph (Advanced)
- Count Independent Sets in Small Graph (Advanced)
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.