← 返回 uber 的题目列表Shortest Subarray with At Least K Different Integers
类型:online_judge
Given an integer array arr and integer k, find the length of the shortest subarray that contains at least k different integers. If there is no such subarray return -1.
Example:
Input: arr = [1, 2, 1, 2, 3], k = 2 Output: 2 Explanation: [1,2] is one of the shortest good subarrays.
Constraints:
1 <= k <= n <= 10^5
0 <= arr[i] < n
Example
Input
5
2
1 2 1 2 3
Output
2