The problem. Given a string s of lowercase letters and a number k, return the length of the longest substring with exactly k distinct characters. If no substring has exactly k, return −1.
s = "aabacbebebe", k = 3 -> 7 ("cbebebe")
s = "aaaa", k = 2 -> -1 (only one kind of letter)
s = "aabbcc", k = 2 -> 4 ("aabb" or "bbcc")Free account
Sign up to read the rest of this lesson: 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come