0PricingLogin
Competitive Programming Academy · Lesson

Variable Window with Two Pointers

Grow and shrink to meet a condition.

When the Window Breathes

Some problems do not fix the window length. Instead the window grows and shrinks to keep a condition true, like a sum staying under a limit.

Two Pointers, One Window

Keep two indices, left and right, marking the window edges. The right pointer expands while left trails behind to shrink when needed.

left = 0
window = 0

All lessons in this course

  1. Fixed-Size Window Sums
  2. Variable Window with Two Pointers
  3. Longest Substring Without Repeats
  4. Count Windows That Satisfy a Rule
← Back to Competitive Programming Academy