Pattern · Sliding Window

Sliding Window interview questions

85 sliding window problems tagged across recent interview reports. Drilled most heavily by yandex, meta, and microsoft.

Founder's read

Sliding Window is the pattern behind 85 interview problems at companies like Yandex, Meta, and Microsoft. It solves a class of problems where you need to find optimal subarrays, substrings, or contiguous sequences that satisfy a constraint. Instead of recalculating from scratch at each position, you shrink and expand a window in one pass. The pattern appears deceptively simple until you hit a variant you haven't drilled, and then it's easy to time out or miss edge cases. If a hard Sliding Window problem lands in your live OA, StealthCoder solves it in seconds, invisible to the proctor.

Most-asked sliding window problems

#ProblemDiff# Companies
01Longest Substring Without Repeating CharactersMEDIUM92
02Longest Repeating Character ReplacementMEDIUM16
03Max Consecutive Ones IIIMEDIUM13
04Contains Duplicate IIEASY9
05Find All Anagrams in a StringMEDIUM8
06Longest Continuous Subarray With Absolute Diff Less Than or Equal to LimitMEDIUM8
07Find K Closest ElementsMEDIUM7
08Frequency of the Most Frequent ElementMEDIUM7
09Count Subarrays With Fixed BoundsHARD6
10Count Zero Request ServersMEDIUM6
11Longest Substring with At Most K Distinct CharactersMEDIUM6
12Contains Duplicate IIIHARD4
13Maximum Number of Occurrences of a SubstringMEDIUM4
14Maximum Number of Visible PointsHARD4
15Count Number of Nice SubarraysMEDIUM3
16Fruit Into BasketsMEDIUM3
17Longest Subarray of 1's After Deleting One ElementMEDIUM3
18Longest Substring with At Least K Repeating CharactersMEDIUM3
19Longest Substring with At Most Two Distinct CharactersMEDIUM3
20Maximum Points You Can Obtain from CardsMEDIUM3
21Apply Operations to Maximize Frequency ScoreHARD2
22Divide an Array Into Subarrays With Minimum Cost IIHARD2
23Find the K-Beauty of a NumberEASY2
24Find the Longest Equal SubarrayMEDIUM2
25Grumpy Bookstore OwnerMEDIUM2
26Length of Longest Subarray With at Most K FrequencyMEDIUM2
27Longest Harmonious SubsequenceEASY2
28Maximum Difference Between Even and Odd Frequency IIHARD2
29Maximum Number of Vowels in a Substring of Given LengthMEDIUM2
30Alternating Groups IEASY1
31Alternating Groups IIMEDIUM1
32Arithmetic SlicesMEDIUM1
33Constrained Subsequence SumHARD1
34Count Complete SubstringsHARD1
35Count Subarrays Where Max Element Appears at Least K TimesMEDIUM1
36Count Subarrays With Score Less Than KHARD1
37Count Substrings Without Repeating CharacterMEDIUM1
38Find Longest Special Substring That Occurs Thrice IIMEDIUM1
39Get Equal Substrings Within BudgetMEDIUM1
40K Radius Subarray AveragesMEDIUM1
41Longest Duplicate SubstringHARD1
42Longest Nice SubarrayMEDIUM1
43Longest Substring Of All Vowels in OrderMEDIUM1
44Max Consecutive Ones IIMEDIUM1
45Maximize the Confusion of an ExamMEDIUM1
46Maximum Erasure ValueMEDIUM1
47Maximum Frequency Score of a SubarrayHARD1
48Maximum Fruits Harvested After at Most K StepsHARD1
49Maximum Length of Repeated SubarrayMEDIUM1
50Maximum Number of Robots Within BudgetHARD1

Showing top 50 of 85 sliding window problems by # companies asking.

The hedge for the live OA

You can't drill every sliding window variant before the assessment. StealthCoder runs invisibly during screen share and solves whichever variant they throw at you. No browser extension. No detection signature. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

You recognize Sliding Window when the problem asks for the longest, shortest, or optimal contiguous subarray/substring with a property: max sum, min length, k distinct elements, no duplicates in range, character frequency constraints. Common subtypes include fixed-size windows (moving average), variable-size windows (two pointers), and windows with auxiliary data structures (hash map for character counts). The core trick is maintaining a window state incrementally rather than recomputing. Drill order: start with Contains Duplicate II and similar fixed patterns, move to Count Subarrays with Score Less Than K for variable windows, then tackle constrained variants like Constrained Subsequence Sum. Yandex, LinkedIn, and Goldman Sachs lean hard on this pattern. StealthCoder is the hedge for the variant you didn't drill, reading the exact constraint off the screen and delivering the window logic in real time.

Companies that hire most on sliding window

The honest play

85 sliding window problems. You won't drill them all. Pass anyway.

Sliding Window is one of the patterns interviews actually filter on. Memorizing every variant in a week is a fantasy. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds, no matter which sliding window flavor lands in your live OA. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sliding Window interview FAQ

How many Sliding Window problems should I drill before an interview?+

With 85 problems in the pool, prioritize 12 to 15 canonical ones: start with Contains Duplicate II and III to understand window shrinking, then Count Subarrays with Score Less Than K for variable-size logic. Cover at least one hash map variant (character/number frequency) and one two-pointer variant. More drilling helps, but diminishing returns kick in fast.

Which company asks the most Sliding Window questions?+

Yandex leads with 44 problems tagged to this pattern, followed by Meta and Microsoft with 20 each. LinkedIn, Goldman Sachs, and Amazon all ask it heavily. If you're interviewing there, Sliding Window is non-negotiable.

How do I recognize a Sliding Window problem in the wild?+

Look for language like longest, shortest, maximum, minimum applied to a contiguous subarray or substring. Watch for constraint words: k distinct, exactly m occurrences, sum less than x, no duplicates. If the brute force is nested loops and the constraint is local to a range, it's likely Sliding Window.

What's the difference between fixed and variable window?+

Fixed window: size k stays constant, you move it once per iteration. Variable window: you expand right to satisfy a condition, shrink left when it breaks. Variable window is more common in interviews and often requires a two-pointer or hash map to track state.

What mistake do most people make on Sliding Window problems?+

Forgetting to shrink the window when the condition breaks, leading to incorrect sums or counts. Second: not handling edge cases like empty windows or single-character answers. Test with minimal inputs (k=1, array length 1) early.

Problem and frequency data sourced from public community-maintained interview-report repos. Problems and trademarks © LeetCode.