← Visualizers
Sliding Window LeetCode 2841

Maximum Sum of Distinct Subarrays With Length K / visualized

A fixed-size window of length k slides across the array. A running sum tracks the window's total, and a frequency map tracks duplicates — the window only counts toward the answer when every value inside it is distinct.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

in window duplicate new max
O(n) time · O(k) space  ·  each element enters and leaves the window exactly once — no re-summing, no re-scanning.