#K51477. Longest Homogeneous Substring
Longest Homogeneous Substring
Longest Homogeneous Substring
Given a string s of length n and an integer k, you are allowed to perform at most k operations. In each operation, you may change any character of s to any other character of your choice. Your task is to determine the maximum length of a contiguous substring consisting of identical characters that can be achieved after performing at most k modifications.
This problem can be formulated as: Find the maximum integer L such that there exists a substring of s of length L which, after at most k operations (i.e., character replacements), contains only one distinct character. The formula for checking a window is:
\[ \text{window\_length} - \text{frequency}(\text{ch}) \leq k \]
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains two space-separated integers: n (the length of the string) and k (the maximum number of allowed operations).
- The second line contains the string s composed of lowercase English letters.
outputFormat
Output a single integer on stdout representing the length of the longest homogeneous substring that can be achieved after at most k modifications.
## sample8 1
aabbccdd
3
</p>