The Smurfs
Submissions: 547   Accuracy:

24.19%

  Difficulty: Medium   Marks: 4

A geek once visited a magical island where he found a special creature. He named it as Smurf. He noticed a very strange thing there. The smurfs resembled the primary colors of light. To make it more clear, the primary colors of light are Red, Green, and Blue. He talked to one of the smurfs. The smurfs came to know that he is a good programmer. The smurfs suggested a deal that they will ask him one question and if he is able to answer that question, they will allow the geek to take anything from the island.

The question is as follows:

The smurfs possess a very magical property. When two smurfs of different colors meet with other, they gets converted into a smurf of the third color. How many minimum number of smurfs will be remaining after this transformation? The question looked simple to geek. However, the smurfs put another constraint to make the geek think more. The two smurfs must be adjacent to each other  to make the transformation take place.

Input:

The first line contains the number of test cases. The next line represents the total number of smurfs in the island. The next line contains colors of smurfsstanding in a queue. Colors of smurfs will be represented by a single character R, G and B.

Output:

Each line in output represents the minimum number of smurfs after transformation corresponding to each test case.

Constraints:

1 <=T<= 50
1 <=N<= 1000

Example:

Input:

3
5
R G B R B
3
R R G
1
R

Output:

1
1
1

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Aashish Barnwal
Author: kartik


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.