← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given an array nums of integers and an integer k, find the length of the smallest subarray within nums that contains at least k distinct integers.
Example 1:
Input: nums = [1,2,1,3,4], k = 3 Output: 2 Explanation: The shortest subarray is [3,4] of length 2, which contains 3 distinct integers: 3, 4, and 1 (from the previous elements).
Example 2:
Input: nums = [1,2,3,4,5], k = 3 Output: 1 Explanation: The shortest subarray is [5], which contains 3 distinct integers: 5, 1, and 2 (from the previous elements).
1 <= nums.length <= 10^51 <= nums[i] <= 10^91 <= k <= nums.length