Number of R's
Practice
4.1 (183 votes)
Algorithms
Approved
Dynamic programming
Medium
Open
Problem
79% Success 23075 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

As we all know RK loves his name very much especially the character 'R' so this time task for you is based on his awesome name. RK gives you a string S consisting of characters 'R' and 'K' only. Now you are allowed to do exactly one move that is you have to choose two indices i and j (1<=i<=j<=|S| where |S| is string length ) and flip all the characters at position X where i<=X<=j. Flipping the character means :

 if S[X]='R' :  //If character at position X is 'R' then change it to 'K'
      S[X]='K'  
 else :          //else if character at position X is 'K' then change it to 'R'
      S[X]='R'

Now your goal is that after exactly one move you have to obtain the maximum number of R's as RK loves this character very much. So help RK with maximum R's.

Input :
The first line contains the number of test cases T. Each test case contains a string S consisting of characters 'R' and 'K' only.

Output :
For each test case print the maximal number of R's that can be obtained after exactly one move.

Constraints:
1<=T<=10
1<=|S| <=10^6 (length of string)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
15 votes
Tags:
AlgorithmsDynamic ProgrammingHiringMedium
Points:30
5 votes
Tags:
Medium
Points:30
8 votes
Tags:
AlgorithmsDynamic ProgrammingMediumString Manipulation