New
ML System Design & SQL tracks just landed
See what's new
×
Question Bank
Pricing
Blog
Forum
HOT
Referral
Description
Solution
Discussion
Submissions
Ask AI
Question Bank
Google
Coding Question
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
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
Qwen
Qwen3.6-Flash
0/2000
Auto
Debug
Run
Submit
Test Cases
Input
Output
Expected