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.
– 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
- Longest streak of days within a budgetPredict
- Longest stretch of a log with no letter seen twiceSpot the bug
- Best total over k consecutive daysFill the blank
- Shortest run of orders that reaches a goalPredict
- Where does a rearranged pattern appear in a text?Predict
- Longest single-colour run after repainting k tilesPick the fix
- Best single buy-then-sell on a price historyPredict
- Longest stretch with at most two kindsPredict
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.
collections.dequeA deque gives O(1) append and pop at both ends;
list.pop(0)is O(n) because it shifts every item.deque(maxlen=k)A deque with maxlen drops the oldest item automatically when a new one is appended at the full size.
itertools.accumulateaccumulate(xs)yields running totals;[0, *accumulate(xs)]gives prefix sums for O(1) range totals.Kotlin
windowedlist.windowed(k)returns every window as a new list: readable, but O(n·k) work and memory.Kotlin
ArrayDequekotlin.collections.ArrayDequesupports addFirst, addLast, removeFirst and removeLast in amortised O(1).
Printable cheat sheet · Review your weak spots in this topic
Share your progress
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