Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

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