How do you find the cheapest flights within at most k stops?
PICTURE THIS: DATA SPLIT
Fit on train, tune on val, report on test once.
Simple meaning
Bellman-Ford style relaxation for k+1 rounds, or BFS/Dijkstra on a state (city, stops).
WHY — Graphs instead of guessing?
Why interviewers care about Graphs:
question about Graphs.
trade-offs, and what you would actually do on a DSA project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens with tokens?
Before the model can read a sentence, it goes through these steps:
- 1Bellman-Ford style relaxation for
k+1 rounds, or BFS/Dijkstra on a state (city, stops).
- 2Constrained Dijkstra is O(E
log V * k) depending on the heap key
- 3k rounds of edge
relaxation are O(k * E).
- 4Plain Dijkstra on city
only is wrong because a costlier path with fewer stops may win later.
- 5Next token
The model scores what should come next.
- 6Decode
IDs turn back into readable text.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
Bellman-Ford style relaxation for k+1 rounds, or BFS/Dijkstra on a state (city, stops). Constrained Dijkstra is O(E log V * k) depending on the heap key