Sliding Window — DSA Pattern

The Sliding Window pattern applies when you need fixed-size, variable-size, and character frequency matching window techniques. Its time complexity is O(n) — each pointer advances at most n times in total and space complexity O(1) for a fixed-size numeric window; O(k) when tracking window contents (k = window size or alphabet size). It is used in 30 problems on Thita, including Calculate Compressed Mean, Contains Duplicate II and Continuous Subarrays. Common variations are Character Frequency Matching and Fixed Size (Subarray Calculation).

Master the sliding window technique for subarray and substring problems. Learn fixed size windows, variable size windows, and monotonic queue optimizations.

Sliding Window is pattern 2 of 16 in the Thita.ai DSA course. It covers fixed-size, variable-size, and character frequency matching window techniques, split into 4 subpatterns and about 2.5 hours of study. It is one of the interview-critical patterns, so it is worth covering before your first onsite.

Subpatterns of Sliding Window

Each subpattern below has its own theory page and problem set. They are listed in the order the course teaches them.

  • Fixed Size (Subarray Calculation) — Learn fixed-size sliding window for subarray calculations like maximum average, moving average, and k-size subarray problems. (core technique)
  • Variable Size (Condition-Based) — Master variable-size sliding window for condition-based problems like longest substring without repeating characters. (core technique)
  • Character Frequency Matching — Learn sliding window with character frequency matching for anagram and permutation substring problems. (important variation)
  • Monotonic Queue for Max/Min — Master monotonic queue (deque) to find maximum or minimum in sliding windows efficiently in O(n) time. (depth topic)

How to practise Sliding Window on Thita.ai

Read the theory for a subpattern, then solve its problems in the browser editor. Your solution runs against the problem's test cases, and the AI coach gives a hint on the technique you are missing rather than the finished answer. Progress is tracked per subpattern, so the tracker shows which of the 4 Sliding Window subpatterns you have covered. Topics covered here include sliding window, sliding window algorithm, subarray problems, substring problems, fixed window, variable window, window sliding technique, maximum subarray.

Related DSA patterns

Preparing this lesson and its course outline.