Problem 2958 · Medium

Length of Longest Subarray With at Most K Frequency

Slide a window across the array, counting each value; when the value just added exceeds k, move the left edge until it is back to k.

Open the interactive visualisation