values and an integer removals.
You may delete at most removals elements from the array (any of them; the rest keep their order). Afterwards, look for the longest contiguous block whose elements are all equal.
Return the greatest length of such a block you can achieve with the best choice of deletions.values=[4, 2, 4, 3, 3, 4, 4], removals=2 → 3
Removing both 3s (positions 3 and 4) gives [4, 2, 4, 4, 4], which has three 4s in a row. Getting four 4s together would also need the 2 removed, which is three removals.
values=[1, 2, 3], removals=0 → 1
Nothing can be removed and all numbers differ, so the longest block of equal values has length 1.
values=[2, 1, 2, 1, 2], removals=2 → 3
Remove both 1s to get [2, 2, 2].
values=[4, 2, 4, 3, 3, 4, 4], removals=2
3
Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.