GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesCheapest K-Stop Flight

Gamified challenge · Bellman-Ford

Cheapest K-Stop Flight

There are n cities, 0 to n - 1. Each entry [from, to, price] of flights is a one-way flight. You start in src and want to reach dst with at most `k` layovers, that is at most k + 1 flights.

Write cheapest(n, flights, src, dst, k) that returns the lowest total price of such a trip, or -1 if there is none. If src == dst the trip is free: return 0.

Example: flights [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]] from 0 to 3. With k = 1 the best is 0 → 1 → 3 for 700; with k = 2, 0 → 1 → 2 → 3 costs 400.

Sign in to play Cheapest K-Stop Flight

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account