Sliding window interview questions

Fixed and variable windows over arrays and strings, the amortised argument that makes them linear, and when a window is the wrong tool.

5 quick facts

– interview-ready · 12 questions in this topic

– of 12 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Questions

  1. Longest streak of days within a budgetPredict
  2. Longest stretch of a log with no letter seen twiceSpot the bug
  3. Best total over k consecutive daysFill the blank
  4. Shortest run of orders that reaches a goalPredict
  5. Where does a rearranged pattern appear in a text?Predict
  6. Longest single-colour run after repainting k tilesPick the fix
  7. Best single buy-then-sell on a price historyPredict
  8. Longest stretch with at most two kindsPredict
  1. Busiest hour in each k-hour spanFill the blank
  2. Fixed-size vs variable-size windowsPick the fix
  3. Why a window with a nested loop is still O(n)Predict
  4. When a sliding window does not workPredict

Practise this topic

Flashcards · 22

Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.

Quick quiz · 12 questions

One exercise per question, checked as you go. Needs JavaScript.

Mock interview · 2 sets

Timed, out loud, then tick what you covered. Needs JavaScript.

Fix this PR · 1 review

Review a diff like a senior: flag the lines you'd comment on. Needs JavaScript.

Quick facts

Recall the answer first, then tap Show to check.

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license