Code Room
CodingMedium
Question
There are n cities (0..n-1) connected by directed flights, where flights[i] = [from, to, price]. Given a source src, a destination dst, and an integer k, return the cheapest price to fly from src to dst using at most k intermediate stops (i.e. at most k+1 flights). If there is no such route, return -1.
Implement
cheapest_flights_k_stops(n: int, flights: list[list[int]], src: int, dst: int, k: int) → intExamples
in
[4,[[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]],0,3,1]out700What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.