Shortest Path LeetCode Problems: All 27, With Python Solutions
Every problem in this library that LeetCode tags Shortest Path — 27 in total, 19 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 27 problems
- 0 Easy
- 15 Medium
- 12 Hard
Shortest Path problems by difficulty
Problems with a complete Python solution are listed first, then by ascending problem number.
Medium (15)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 399 | Evaluate Division | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
| 743 | Network Delay Time | Medium | Depth-First Search, Breadth-First Search, Graph +2 |
| 787 | Cheapest Flights Within K Stops | Medium | Depth-First Search, Breadth-First Search, Graph +3 |
| 1334 | Find the City With the Smallest Number of Neighbors at a Threshold Distance | Medium | Graph, Dynamic Programming, Shortest Path |
| 1514 | Path with Maximum Probability | Medium | Graph, Array, Shortest Path +1 |
| 1786 | Number of Restricted Paths From First to Last Node | Medium | Graph, Topological Sort, Dynamic Programming +2 |
| 1976 | Number of Ways to Arrive at Destination | Medium | Graph, Topological Sort, Dynamic Programming +1 |
| 2662 | Minimum Cost of a Path With Special Roads | Medium | Graph, Array, Shortest Path +1 |
| 2976 | Minimum Cost to Convert String I | Medium | Graph, Array, String +1 |
| 505 | The Maze IIPremium | Medium | Depth-First Search, Breadth-First Search, Graph +4 |
| 1810 | Minimum Path Cost in a Hidden GridPremium | Medium | Depth-First Search, Breadth-First Search, Graph +5 |
| 2093 | Minimum Cost to Reach City With DiscountsPremium | Medium | Graph, Shortest Path, Heap (Priority Queue) |
| 2297 | Jump Game VIIIPremium | Medium | Stack, Graph, Array +3 |
| 2473 | Minimum Cost to Buy ApplesPremium | Medium | Graph, Array, Shortest Path +1 |
| 2737 | Find the Closest Marked NodePremium | Medium | Graph, Array, Shortest Path +1 |
Hard (12)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 882 | Reachable Nodes In Subdivided Graph | Hard | Graph, Shortest Path, Heap (Priority Queue) |
| 1368 | Minimum Cost to Make at Least One Valid Path in a Grid | Hard | Breadth-First Search, Graph, Array +3 |
| 2045 | Second Minimum Time to Reach Destination | Hard | Breadth-First Search, Graph, Shortest Path |
| 2203 | Minimum Weighted Subgraph With the Required Paths | Hard | Graph, Shortest Path |
| 2290 | Minimum Obstacle Removal to Reach Corner | Hard | Breadth-First Search, Graph, Array +3 |
| 2577 | Minimum Time to Visit a Cell In a Grid | Hard | Breadth-First Search, Graph, Array +3 |
| 2642 | Design Graph With Shortest Path Calculator | Hard | Graph, Design, Shortest Path +1 |
| 2699 | Modify Graph Edge Weights | Hard | Graph, Shortest Path, Heap (Priority Queue) |
| 2959 | Number of Possible Sets of Closing Branches | Hard | Bit Manipulation, Graph, Enumeration +2 |
| 2977 | Minimum Cost to Convert String II | Hard | Graph, Trie, Array +3 |
| 499 | The Maze IIIPremium | Hard | Depth-First Search, Breadth-First Search, Graph +5 |
| 2714 | Find Shortest Path with K HopsPremium | Hard | Graph, Shortest Path, Heap (Priority Queue) |
Keep exploring
All LeetCode topicsEvery tag with a page of its own, with the number of problems behind each.LeetCode patternsThe techniques themselves, with a Python template and complexity for each.Curated study listsBlind 75, NeetCode 150 and three more, grouped by pattern.Easy problemsStart here when the data structure is new rather than the problem.
Other topics
- Array1,569
- String672
- Hash Table588
- Math485
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
When the Shortest Path problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.