DSA in Python – Cheapest Flights Within K Stops | Leetcode 787 | Modified BFS | Part 150 [Hindi]
1.5K views on YouTube
π Welcome to Part 150 of Code & Debugβs DSA Python Course 2025!
In this video, we solve Leetcode 787 – Cheapest Flights Within K Stops, a practical graph problem where weβre asked to find the minimum cost to travel from a source to destination within at most K stops.
This isnβt a classic shortest-path problem β we need to modify BFS/Dijkstra to include a constraint on the number of stops.
π¨βπ« Whatβs covered in this video:
β
Graph construction from flight list
β
Modified BFS traversal with (steps, node, cost)
β
Pruning paths that exceed k + 1 stops
β
Tracking minimum cost per node
β
Understanding when to update cost and when not to
β
Step-by-step Python code walkthrough
β
Time and Space Complexity Analysis
This is a perfect example of adapting graph traversal to real-world constraints like limited layovers or flight hops.
π Leetcode 787 – Cheapest Flights Within K Stops:
https://leetcode.com/problems/cheapest-flights-within-k-stops/description/
π Refer to the article for better understanding:
π https://codeanddebug.in/blog/cheapest-flights-within-k-stops-leetcode-787-easy-bfs-approach-in-python/
π Full Playlist Sheet (All Questions in Order):
https://docs.google.com/spreadsheets/d/1AWE15Fy3wD2iqu2vjK_R7cCiuvSsjYQclcdZmHpF66o/edit?usp=sharing
π Enroll in the FREE Python DSA Course:
https://codeanddebug.in/course/master-dsa-with-leetcode
π Master the Full DSA Track (Zero to Hero):
https://codeanddebug.in/course/zero-to-hero-python-dsa
Keep going strong and stay consistent with Code & Debug!
Like | Share | Subscribe & turn on the bell for updates!
#CheapestFlights #Leetcode787 #GraphBFS #DSA2025 #PythonDSA #GraphWithConstraints #KStops #GraphTraversal #CodeAndDebug #Part150