CodeMosa

Master LeetCode Patterns

5 Problems

Sliding Window Problems

A curated list of classic Sliding Window problems with quick explanations and links to code templates.

Back to Collections

Relevant Patterns

#
Study these pattern guides before tackling the problems. Understanding the core concepts will help you solve them more efficiently.

Practice Problems

#
1
Max Sum Subarray of Size K
Easy0
Show 2 hints
  • Use a fixed-size window of k elements.
  • Initialize the sum of the first k, then slide: subtract left, add right.
Show 2 hints
  • Map char → last index; move left to max(left, lastIndex+1) on repeat.
  • Window length is right-left+1; keep best seen.
Show 2 hints
  • Window size equals pattern length; maintain frequency diff.
  • When all counts are zero (or matched == uniqueChars), record left index.
Show 2 hints
  • Track max frequency in current window.
  • If window size − maxFreq > k, shrink left; answer is max window length.
Show 2 hints
  • Maintain counts for required characters; decrement when matched.
  • When need == 0, try to shrink from left while valid.

Track Your Progress

Mark problems as complete as you solve them. Come back anytime to continue where you left off.