Longest Frequency-Bounded Subarray
Problem statement
Return the maximum length of a contiguous subarray in which no distinct value occurs more than k times.
Function
longestFrequencyBoundedSubarray(values: int[], k: int) → intExamples
Example 1
values = [1,1,2,3]k = 1return = 3The reported maximum follows the per-value frequency bound.
Example 2
values = [1,2,1,3,2]k = 1return = 3The reported maximum follows the per-value frequency bound.
Constraints
1 <= values.length <= 1000001 <= k <= values.length