Search
⌘K
Leetcode 340. Longest Substring with At Most K Distinct Characters
Given a string and an integer K, find the length of the longest substring that contains at most K distinct characters. This is typically solved by maintaining a variable-size sliding window and a character frequency map to expand and shrink while keeping the distinct-count constraint.
Asked at:
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Late April, 2026
Mid-level
Hello Interview Premium
Your account is free and you can post anonymously if you choose.