DataDriven
LearnPracticeInterviewDiscussDaily
HelpContactPrivacyTermsSecurityiOS App

© 2026 DataDriven

Loading lesson...

  1. Home
  2. Learn
  3. Sliding Window: Intermediate

Sliding Window: Intermediate

Variable windows, frequency maps, and the tricks that separate senior engineers from the rest.

Variable windows, frequency maps, and the tricks that separate senior engineers from the rest.

Category
Python
Difficulty
intermediate
Duration
40 minutes
Challenges
0 hands-on challenges

Topics covered: Variable-Size Windows: The Left Pointer Wakes Up, Character Frequency Maps: Windows Inside Strings, Minimum Window Substring: The Gold Standard Problem, At-Most-K: Generalizing Window Constraints, DE Applications: Rate Limiting, Sessionization, and Top-K Deque

Lesson Sections

  1. Variable-Size Windows: The Left Pointer Wakes Up (concepts: pyVariableWindow, pyTwoPointer)

    In a fixed-width window, the left pointer is a zombie. It moves exactly one step for every step the right pointer takes. In a variable-size window, the left pointer has agency. It moves zero or more steps after each expansion of the right pointer, driven entirely by whether the window constraint is satisfied. This is the conceptual leap. The right pointer always advances. The left pointer advances only when the window is invalid. The gap between them, right - left + 1, is the window size, and it

  2. Character Frequency Maps: Windows Inside Strings (concepts: pyFrequencyMap, pyAnagramWindow, pyMatchesCounter)

    A large class of intermediate sliding window problems involve strings where the window state is not a simple sum or set but a frequency map: a dictionary counting how many times each character appears in the current window. The pattern shows up in anagram detection, permutation matching, and, in data engineering, log token matching and pattern detection in event streams. The mechanics are always the same: when a character enters the window, increment its count; when a character leaves, decrement

  3. Minimum Window Substring: The Gold Standard Problem (concepts: pyMinWindow, pyHaveNeed, pyVariableWindowAdvanced)

    Minimum Window Substring (LeetCode 76) is the problem that separates candidates who memorized patterns from candidates who understand them. It is the hardest problem that still has a clean O(n) solution. It combines variable-size windows with frequency map tracking and a subtle validity condition. At companies like Meta, Stripe, and Databricks, this problem or a direct variant of it appears regularly in senior DE loops. Here is the approach that interviewers love: the have/need (also called form

  4. At-Most-K: Generalizing Window Constraints (concepts: pyAtMostK, pyExactlyK, pySubarrayCount)

    A whole class of sliding window problems uses the phrase 'at most K distinct elements.' Longest substring with at most K distinct characters. Maximum subarray with at most K unique values. Subarrays with at most K odd numbers. The constraint is a ceiling on some property of the window, not an exact value. This is straightforward to implement: maintain a counter, and whenever the number of distinct elements exceeds K, contract left. But there is a deeper trick here that interviewers love to probe

  5. DE Applications: Rate Limiting, Sessionization, and Top-K Deque (concepts: pyRateLimiter, pySessionization, pyMonotonicDeque)

    The intermediate sliding window problems you have learned in this lesson are not just interview exercises. They map directly to production DE patterns that senior engineers implement regularly. When you close your LeetCode tab and open a Kafka Streams job or a Flink application, the same algorithmic building blocks are there: variable-size time windows, frequency maps over event streams, and sliding deques for top-K queries. Knowing how to bridge the interview problem to the production system is

Related

  • All Lessons
  • Practice Problems
  • Mock Interview Practice
  • Daily Challenges