# Cheapest Flights Within K Stops (Practice 5072): Walkthrough

Interviewers use this pattern to test whether you can state the invariant before coding. Here is a compact rehearsal note.

## Approach

Bellman-Ford limited to k+1 rounds, copying the distance array each round so paths don't chain.

```python
def find_cheapest(n,flights,src,dst,k):
INF=float('inf');d=[INF]*n;d[src]=0
for _ in range(k+1):
nd=d[:]
for u,v,w in flights:
if d[u]+w d=nd
return -1 if d[dst]==INF else d[dst]
```

## Complexity

Linear in the dominant input size for the scan; heap/tree variants add a log factor.

## Interview pitfalls

State the invariant out loud, name the complexity, then code. Skipping the invariant is the usual fail mode.

## Practicing out loud

Narrate the approach, complexity and one edge case in under a minute. Disclosure: I work on Linkjob AI, a real-time interview assistant. If you want live practice help, see interview copilot app.