FastPrepLongest Frequency-Bounded Subarray

Longest Frequency-Bounded Subarray

ZipRecruiter logoZipRecruiter● MediumFULLTIMENEW GRADOA
Learn

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) → int

Examples

Example 1

values = [1,1,2,3]k = 1return = 3

The reported maximum follows the per-value frequency bound.

Example 2

values = [1,2,1,3,2]k = 1return = 3

The reported maximum follows the per-value frequency bound.

Constraints

  • 1 <= values.length <= 100000
  • 1 <= k <= values.length

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int longestFrequencyBoundedSubarray(int[] values, int k) {
    // Write your code here.
}
values[1,1,2,3]
k1
expected3
Checking account…