pyassistant

Longest substring with at most k distinct chars each appearing at least m times

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.

Example:

Input:
('aaabbccddeee', 2, 2)
Output:
5

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.