Topics/Queue & Deque/Recent requests

Pattern

Recent requests

Recent requests is a reusable approach under Queue & Deque. Once you recognize the shape of the input and the ask, this pattern gives you a standard plan instead of inventing a new algorithm from scratch.

Queue & DequeLinear DSPattern

When to use it

Reach for Recent requests when a queue & deque problem matches the cues in this lesson — especially after you’ve ruled out a brute-force nested scan.

How it works

  1. Restate the Queue & Deque problem in one sentence and name the constraint that Recent requests exploits.
  2. Sketch the invariant Recent requests maintains (what stays true after each step).
  3. Walk a tiny example by hand, writing the state after every update.
  4. Translate that walk into code in your interview language, then list edge cases.

Solution

Reference implementation in C#, Python, Java, JavaScript, and C++.

Exact solutionRecent requests

Why interviewers care

Interviewers grade pattern recognition. Naming Recent requests early shows you can classify the problem inside Linear DS.

Drill Recent requests with Queue & Deque problems — filter the bank and solve 2–3 Easy/Medium items while saying the invariant out loud.

Watch-outs

  • !Using list.shift in JS (O(n))
  • !Forgetting to expire out-of-window indices
Loading visualization…

Practice this

Related Queue & Deque problems — open any one and apply Recent requests.

Search bank →

More under Queue & Deque

← Back to Queue & Deque lesson