values and an integer cap. A window of the array (one or more consecutive elements) is good if no value occurs in it more than cap times.
Return the length of the longest good window.values=[4, 4, 1, 4, 2, 1, 1], cap=2 → 5
The window [4, 1, 4, 2, 1] has length 5 with two 4s and two 1s. Anything longer brings in a third 4 or a third 1.
values=[3, 3, 3], cap=1 → 1
Each number may appear only once, so only a window of length 1 fits.
values=[5, 6, 7, 5], cap=3 → 4
values=[4, 4, 1, 4, 2, 1, 1], cap=2
5
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.