Find minimum subarray length with k distinct integers
Problem: Minimum Subarray Length with Exactly K Distinct Integers
Given an integer array arr and an integer k, find the minimum length of a contiguous subarray that contains exactly k distinct integer values.
Return the minimum length, or -1 if no such subarray exists.
Constraints and Notes:
- The input array
arrcan contain duplicate integer values. - A subarray is defined as a contiguous slice of the original array.
AI interview prep
Core dilemma
Efficiently tracking the count of distinct elements within a dynamically sized sliding window while strictly adhering to the 'exactly k' constraint, which is more complex than 'at least k' or 'at most k'.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Find minimum subarray length with k distinct integers
Problem: Minimum Subarray Length with Exactly K Distinct Integers
Given an integer array arr and an integer k, find the minimum length of a contiguous subarray that contains exactly k distinct integer values.
Return the minimum length, or -1 if no such subarray exists.
Constraints and Notes:
- The input array
arrcan contain duplicate integer values. - A subarray is defined as a contiguous slice of the original array.