Longest substring with k distinct

Write codeMedium28 minMeta style

Your task

Given a string s and integer k, return the length of the longest substring that contains at most k distinct characters. If k is 0, the answer is 0. Constraints: 0 <= len(s) <= 5*10^4, 0 <= k <= 26, s is lowercase letters.

Examples

longest_k_distinct(s: str, k: int) -> int
Example 1
Inputlongest_k_distinct("eceba", 2)
Output3