All Tracks Algorithms Graphs Graph Representation Problem

Uniformity
Tag(s):

Algorithms, Easy, Graph Representation, Graphs

Problem
Editorial
Analytics

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\).
 

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

Indeed India Operations Pvt Ltd

Challenge Name

She codes, Indeed challenge 2019

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?