High Graphs Question 178 of 224

How do you find the cheapest flights within at most k stops?

DSA interview set · Speak this in 60–90 seconds · Faridabad & Delhi NCR

PICTURE THIS: DATA SPLIT

Train 70%Val 15%Test 15%

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).

1

WHY — Graphs instead of guessing?

Why interviewers care about Graphs:

This is a process

question about Graphs.

Panels listen for order,

trade-offs, and what you would actually do on a DSA project - not buzzwords.

Stay structured

Name the idea, why it exists, then one short example.

Close cleanly

End with when you use it and one common pitfall.

2

STEPS — What happens with tokens?

Before the model can read a sentence, it goes through these steps:

  1. 1
    Bellman-Ford style relaxation for

    k+1 rounds, or BFS/Dijkstra on a state (city, stops).

  2. 2
    Constrained Dijkstra is O(E

    log V * k) depending on the heap key

  3. 3
    k rounds of edge

    relaxation are O(k * E).

  4. 4
    Plain Dijkstra on city

    only is wrong because a costlier path with fewer stops may win later.

  5. 5
    Next token

    The model scores what should come next.

  6. 6
    Decode

    IDs turn back into readable text.

3

EXAMPLE — See it in action

Here's a short line you can speak, broken into clear beats:

Say this line
“Constrained Dijkstra is O(E log V * k) depending on the heap key”
Break into beats
ConstrainedDijkstraisOElog
Speaking order
2987408337471632900

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

Chat with us