Problem · Array
Minimum Length Good Subarray
Learn this problemProblem statement
Given an array arr of n positive integers and an integer k, a contiguous subarray is good if it contains at least k distinct integers.
Return the minimum length of a good subarray. If no good subarray exists, return -1.
Function
findMinimumLengthSubarray(arr: int[], k: int) → intExamples
Example 1
arr = [2,2,1,1,3]k = 3return = 4The full array and the subarray [2,1,1,3] each contain the three distinct integers 1, 2, and 3. The latter has length 4, and no shorter subarray contains all three values.
Constraints
1 <= arr.length <= 10^51 <= arr[i] <= 10^91 <= k <= arr.length