Given a string s and integers k and m, find the length of the longest substring of s that contains at most k distinct characters and in which every distinct character appears at least m times. Return 0 if no such substring exists. Constraints & notes: - s consists of ASCII characters (you may assume it's not extremely long for typical medium difficulty limits). - k and m are positive integers (k >= 1, m >= 1). - The substring must satisfy both conditions simultaneously: no more than k distinct characters, and every character present in the substring appears at least m times. Write a function solve(s: str, k: int, m: int) -> int that returns the length of the longest valid substring.
('aaabbccddeee', 2, 2)5