← 返回 bytedance 的题目列表Longest Substring with At Most K Distinct Characters
类型:online_judge
Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.
Example
Input: s = "eceba", k = 2
Output: 3
Explanation: The longest valid substring is "ece".
Constraints (typical)
0 <= len(s) <= 2e5
0 <= k <= 256
s consists of ASCII letters (or lowercase letters; clarify in interview).
Example
Input
eceba
2
Output
3