0Pricing
Competitive Programming Academy · Lesson

Count Windows That Satisfy a Rule

At-most-K minus at-most-(K-1) trick.

Counting, Not Measuring

Sometimes you must count subarrays meeting a rule, not find the longest one. A small trick turns this into easy sliding-window work. 🔢

The Exactly-K Challenge

Counting subarrays with exactly K of something directly is awkward. The boundary keeps flipping, which makes a single clean window hard.

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