Uniformity
Practice
3.3 (34 votes)
Algorithms
Easy
Graphs
Problem
87% Success 4588 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a string that contains only three characters \(a\), \(b\), and \(c\). You can change at the most \(k\) characters in the string. The uniformity index of a string is defined by the maximum length of the substring that contains the same character. Your task is to determine the maximum uniformity index than can be achieved.
Input format
- First line: Two integers \(n\) and \(k\) where \(n\) denotes the size of the string and \(k\) as specified in the question
- Second line: A string of length \(n\)
Output format
Print a single integer denoting the maximum uniformity that can be achieved.
Constraints
\(1 \le N \le 10^6\)
\(0 \le K \le N\)
The string \(s\) contains only characters \(a\), \(b\), and \(c\).
Sample Input
8 1 aabaacaa
Sample Output
5
Explanation
The array can be changed to \(aaaaacaa\) or \(aabaaaaa\).
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:20
254 votes
Tags:
ApprovedEasyGraphsOpenTrees
Points:20
78 votes
Tags:
AlgorithmsGraphs
Points:20
4 votes
Tags:
GraphsReal worldGraph RepresentationData StructuresAlgorithms
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor