Back to problems

Longest Substring with At Most K Distinct Characters

Algorithm · ByteDance · Medium

Requirements Given a string s along with an integer k, determine the maximum length of any contiguous portion of s containing no more than k different characters. Example: The substring "aaba" has length 4 and only the two character types a and b, and no longer contiguous substring meets the limit. Preparation Practice writing the sliding-window pattern and applying it across related tasks, including lengthOfLongestSubstring, K Distinct, and Longest Substring with At Most…

Checking your access…