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:

LinkedIn

LinkedIn


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Late April, 2026

LinkedIn

LinkedIn

Mid-level

Your account is free and you can post anonymously if you choose.