Sliding Window (max sum) Playground

Jaya’s frame over the belt of rice bags: how many bags are read for the total of k when the frame slides? The longest run with no repeated variety, the max of…

Why it matters

Moving averages on a chart, per-minute API rate limits, the longest substring, spike detection: all sliding windows. The key is one question: can what leaves be "undone"? A total can (subtract it), varieties can (note them in a Map), a maximum cannot, and needs a queue.

The key idea

Two neighbouring frames share almost everything

Common mistakes

Try it in this playground