Longest window with at most k distinct values
CodingMediumCorroborated · 4 reportsLast seen Aug 19, 2026
The question
Given an array and an integer k, return the length of the longest contiguous window containing at most k distinct values. Follow-up: return the window itself, and handle a streaming input where you cannot revisit earlier elements.
No write-up yet
We have the question but not yet a full breakdown. If you were asked this, the fastest way to improve the page is to say what the interviewer pushed on.
Add what you remember →4 people reported this question.
I was asked this tooAlso reported at Anthropic, Uber, Perplexity.