The sliding window trick
Tap to start →
Slide the window: add the new number, drop the old one.
Biggest sum of exactly k numbers in a row.
Grow the right side. While the rule breaks, shrink the left.
Each number enters once and leaves once.
Shrinking a variable window with if. It may need to shrink more than once: use while.
Tap an answer. The full video explains why.
Free DSA in Java course. Subscribe to Compiled Canvas on YouTube.