992. Subarrays with K Different Integers
Problem Statement
Given an integer array nums
and an integer k
, return the number of good subarrays of nums
.
A good array is an array where the number of different integers in that array is exactly k
.
For example,
[1,2,3,1,2]
has3
different integers:1
,2
, and3
.
A subarray is a contiguous part of an array.
Example 1:
Example 2:
Constraints:
1 <= nums.length <= 2 * 104
1 <= nums[i], k <= nums.length
Intuition
Links
Video Links
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Previous1423. Maximum Points You Can Obtain from CardsNext2841. Maximum Sum of Almost Unique Subarray
Last updated