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)

#ProblemDifficultyTopics
399Evaluate DivisionMediumDepth-First Search, Breadth-First Search, Union Find +4
743Network Delay TimeMediumDepth-First Search, Breadth-First Search, Graph +2
787Cheapest Flights Within K StopsMediumDepth-First Search, Breadth-First Search, Graph +3
1334Find the City With the Smallest Number of Neighbors at a Threshold DistanceMediumGraph, Dynamic Programming, Shortest Path
1514Path with Maximum ProbabilityMediumGraph, Array, Shortest Path +1
1786Number of Restricted Paths From First to Last NodeMediumGraph, Topological Sort, Dynamic Programming +2
1976Number of Ways to Arrive at DestinationMediumGraph, Topological Sort, Dynamic Programming +1
2662Minimum Cost of a Path With Special RoadsMediumGraph, Array, Shortest Path +1
2976Minimum Cost to Convert String IMediumGraph, Array, String +1
505The Maze IIPremiumMediumDepth-First Search, Breadth-First Search, Graph +4
1810Minimum Path Cost in a Hidden GridPremiumMediumDepth-First Search, Breadth-First Search, Graph +5
2093Minimum Cost to Reach City With DiscountsPremiumMediumGraph, Shortest Path, Heap (Priority Queue)
2297Jump Game VIIIPremiumMediumStack, Graph, Array +3
2473Minimum Cost to Buy ApplesPremiumMediumGraph, Array, Shortest Path +1
2737Find the Closest Marked NodePremiumMediumGraph, Array, Shortest Path +1

Hard (12)

#ProblemDifficultyTopics
882Reachable Nodes In Subdivided GraphHardGraph, Shortest Path, Heap (Priority Queue)
1368Minimum Cost to Make at Least One Valid Path in a GridHardBreadth-First Search, Graph, Array +3
2045Second Minimum Time to Reach DestinationHardBreadth-First Search, Graph, Shortest Path
2203Minimum Weighted Subgraph With the Required PathsHardGraph, Shortest Path
2290Minimum Obstacle Removal to Reach CornerHardBreadth-First Search, Graph, Array +3
2577Minimum Time to Visit a Cell In a GridHardBreadth-First Search, Graph, Array +3
2642Design Graph With Shortest Path CalculatorHardGraph, Design, Shortest Path +1
2699Modify Graph Edge WeightsHardGraph, Shortest Path, Heap (Priority Queue)
2959Number of Possible Sets of Closing BranchesHardBit Manipulation, Graph, Enumeration +2
2977Minimum Cost to Convert String IIHardGraph, Trie, Array +3
499The Maze IIIPremiumHardDepth-First Search, Breadth-First Search, Graph +5
2714Find Shortest Path with K HopsPremiumHardGraph, Shortest Path, Heap (Priority Queue)

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.