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
https://leetcode.com/problems/subarrays-with-k-different-integers/description/
Video Links
Approach 1:
C++
Approach 2:
C++
Approach 3:
C++
Approach 4:
C++
Similar Problems
https://leetcode.com/problems/binary-subarrays-with-sum/description/ https://leetcode.com/problems/count-number-of-nice-subarrays/description/
Previous1423. Maximum Points You Can Obtain from CardsNext2841. Maximum Sum of Almost Unique Subarray
Last updated