Skip to lesson
Exit
The Interview Loop, Stage by Stage1 / 2

1 min lesson

A token-bucket rate limiter

Use the example in "A token-bucket rate limiter" to explain the main idea in plain words.

Step 1 of 2

A token-bucket rate limiter - the kind of infra-flavored problem you might get, written cleanly under timets
type Bucket = { tokens: number; last: number };

function makeLimiter(ratePerSec: number, burst: number) {
  const buckets = new Map<string, Bucket>();
  return function allow(key: string, now = Date.now()): boolean {
    const b = buckets.get(key) ?? { tokens: burst, last: now };
    const refill = ((now - b.last) / 1000) * ratePerSec;
    b.tokens = Math.min(burst, b.tokens + refill);
    b.last = now;
    if (b.tokens < 1) { buckets.set(key, b); return false; }
    b.tokens -= 1;
    buckets.set(key, b);
    return true;
  };
}
Interview move

Narrate as you code. Saying "I'll use a heap here so the next-smallest is O(log n)" turns a silent screen into a conversation and gives the interviewer a chance to nudge you. Silence reads as either stuck or sloppy and you have no AI to bail you out.

Don't fake recall you don't have

Truth-seeking is a Cursor value and it applies in real time. If you blank on an API or a complexity, say so and reason it out rather than confidently inventing it. "I think Dijkstra is O(E log V) with a binary heap, let me sanity-check that" beats stating a wrong number with false certainty.