ALOVEG!! [Easy-Medium]
Practice
3.6 (7 votes)
Easy
Problem
63% Success 2376 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Gurpreet loves his crush A(secret) very much. Recently he forgot her birthday that made "A" very upset.
Gurpreet tried lot to make her happy and asked her to forgive him once. Finally "A" changed her mood and gave Gurpreet a task to prove his love.

The task is :

Given a string str consisting of characters 'A' and 'G' only. Now "A" asks the maximum number of A's in the given string. But there's a twist you have to choose a substring of range [l,r].

where 1<=l<=r<=length(str).

And flip all the characters in choosen range [l,r]. If character is 'A' then change it to 'G' and if it is 'G' then change it to 'A'.

As Gurpreet loves "A" very much so he does not want to make her upset again. Help him with maximum A's.


NOTE:It is necessary for Gurpreet to choose a segment.
input :
first line is T (Number of Test Cases)
Next T lines contain a String.

output :
print T lines with maximum number of A's.

CONSTRAINTS:
1 ≤ T ≤ 10
1 ≤ length(str) ≤ 105

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
14 votes
Tags:
Dynamic ProgrammingEasyRecursion
Points:30
97 votes
Tags:
Dynamic ProgrammingEasyOpenRecursion
Points:30
60 votes
Tags:
Dynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1