Shortest Path Problems for Coding Interviews
25 Shortest Path problems from real coding interviews, each with test cases you can run online. By difficulty they split into 2 basic, 11 intermediate and 12 advanced. The companies that ask them most often are Amazon, Google, Microsoft, Bloomberg.
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
- Buy Two Chocolates (Basic)
- Shortest Route in Weighted Graph (Intermediate)
- Shortest Path With One Free Edge (Intermediate)
- Count Shortest Paths (Advanced)
- Shortest Path With Alternating Colours (Intermediate)
- Shortest Path In Binary Grid (Intermediate)
- Network Delay Time (Advanced)
- Shortest Path Through Maze Keys and Doors (Advanced)
- Shortest Path With Limited Color Changes (Intermediate)
- Minimum Cost to Reach Target With Coupons (Intermediate)
- Minimum Cost Tickets (Advanced)
- Minimum Depth of Binary Tree (Basic)
- Directions Between Two Tree Nodes (Intermediate)
- Cheapest Flights Within K Stops (Intermediate)
- Shortest Path Visiting All Nodes (Advanced)
- Total Cost to Hire K Workers (Advanced)
- Order Book Matching Volume (Advanced)
- Sum of All-Pairs Shortest Paths (Intermediate)
- Shortest Paths With Negative Edges (Advanced)
- Kth Shortest Path Length (Advanced)
- Minimum Cost to Reach City With Discounts (Advanced)
- Cheapest Route With One Half-Price Flight (Advanced)
- Number of Cheapest Routes (Advanced)
- Nodes on Some Shortest Path (Intermediate)
- Cheapest Phone Plan for Usage (Intermediate)
Related
- Intermediate Shortest Path problems
- Advanced Shortest Path problems
- Practice coding problems online
- All interview guides
Frequently asked questions
How do I get good at shortest path 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 shortest path 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.