# Equal Number Of Boys And Girls

Posted: 7 Mar, 2021

Difficulty: Moderate

#### There are ‘N’ students standing in a row. Students are comprised of both girls and boys. Kevin is their teacher, who wants to pick a group of students that have an equal number of boys and girls. Kevin does not want to disturb the whole row and so, he only wants to pick students that are adjacent to each other. Formally, he can only pick a subarray, not a subsequence.

#### A complete row is given as an array of characters (as a string 'S'), you have to find the length of the longest such subarray which follows the above criteria.

##### Input Format:

```
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.
```

##### Output Format:

```
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.
```

##### Note:

```
You don’t need to print anything; it has already been taken care of. Just implement the given function.
```

##### Constraints:

```
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
```

SIMILAR PROBLEMS

Best time to buy and sell stock II

Posted: 5 Sep, 2022

Difficulty: Moderate

LRU Cache

Posted: 10 Sep, 2022

Difficulty: Moderate

Ninja And The Class Room

Posted: 19 Sep, 2022

Difficulty: Easy

Array Rotation

Posted: 21 Oct, 2022

Difficulty: Easy

Find The Single Element

Posted: 30 Oct, 2022

Difficulty: Easy