LeetCode 787. Cheapest Flights Within K Stops | Dijkstra Solution Explained [2022]

Опубликовано: 24 Март 2026
на канале: Shiran Afergan
15,293
408

Tutorial for how to use Dijkstra’s shortest path algorithm to solve “Cheapest Flights Within K Stops ” [LeetCode 787].

*** Edit ***
LeetCode added a test that the code in the video (and in the official solution page) does not pass. The code below passes all the test cases.
https://pastebin.com/5cEzXnPJ
*************

I recommend watching the Dijkstra video before this one. Link here -
Dijkstra's algorithm & code explanation:    • Dijkstra’s Algorithm for Coding Interviews...  

You can find the question here -
https://leetcode.com/problems/cheapes...

The solution code is here -
https://pastebin.com/5cEzXnPJ