Product
Pricing
Blog
Forum
NEW
Referral
Description
Solution
Discussion
Submissions
Ask AI
AI Insights
Quick Summary
Find the length of the shortest contiguous subarray containing at least k distinct integers.
Dynamically adjust the window boundaries to maintain the distinct count constraint.
Return -1 if the entire array lacks enough unique elements to form a valid subarray.
What This Tests
Dynamic window management with two pointers
Frequency tracking using hash maps or fixed-size arrays
Optimizing beyond brute-force range checking
Edge case handling for minimal windows and duplicate-heavy inputs
Common Patterns
Sliding Window
Two Pointers
Hashing
Collapse
Hint 1
Hint 2
What Interviewers May Ask Next
Report
Report seen similar question in interview
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
python
Auto
Debug
Run
Submit
Test Cases
Input
Output
Expected