
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a single integer ‘N’ which represents the number of students in the row.
The second line of each test case contains a string ‘S’ of length ‘N’ which is comprised of two characters ‘G’ and ‘B’ where ‘B’ denotes Boy and ‘G’ denotes the Girl.
For each test case, print the length of the longest possible subarray that Kevin pick so that students are adjacent to each other.
Output for every test case will be printed in a separate line.
You don’t need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10000
S[ i ] = ‘B’ or ‘G’
Where S[i] denotes the ‘i-th’ character of the given string ‘s’.
Time limit: 1 sec
The basic idea of this approach is to loop through each subarray and find the length of the longest subarray which satisfies the property mentioned in the problem statement.
The basic idea of this approach is to traverse through the string and keeps calculating the number of boys and girls and pick subarrays that satisfy the criteria and then finally, select the subarray that has the maximum length.
The basic idea of this approach is to store the count of boys and girls (relatively) and keep iterating through ‘s’ and whenever found the same count again then check of the longest subarray.