← All templates

Sliding Window (Max window)

Pro

Use when you want the maximum length window that satisfies a constraint, where:

  • You can grow by adding s[rhs]
  • If constraint breaks, you can fix it by shrinking from the left

Keywords for identifying Max Window Problems

→ “longest / maximum length”

→ “at most k …”

→ “no more than …”

→ “contains at most / at least”

→ “make window valid again by moving left”

Unlock the Sliding Window (Max window) template

Get the full code template and worked LeetCode examples for Sliding Window (Max window) — plus every other pattern in the library — with a one-time $29 lifetime upgrade.

Upgrade to ProSee free Binary Search template →
Sliding Window (Max window) · Templates · Grind Patterns