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
- Fixed-Size Window Sums
- Variable Window with Two Pointers
- Longest Substring Without Repeats
- Count Windows That Satisfy a Rule