#K3051. Taco Rearrangement Challenge

    ID: 24872 Type: Default 1000ms 256MiB

Taco Rearrangement Challenge

Taco Rearrangement Challenge

You are given an integer n representing the length of a string and a string s containing only lowercase English letters. Your task is to determine if it is possible to rearrange the characters of s to produce a string that contains exactly \(n-2\) occurrences of the letter \(a\) and exactly 2 occurrences of the letter \(b\). In other words, check whether the frequency of \(a\) in s equals \(n-2\) and the frequency of \(b\) equals 2.

Note: You must read input from standard input (stdin) and write your output to standard output (stdout). The input begins with an integer T denoting the number of test cases, followed by T test cases. Each test case is represented by a line containing an integer n and a string s.

inputFormat

The first line contains an integer T, the number of test cases. Each subsequent line contains a test case with two space-separated values: an integer n and a string s. The string s contains only lowercase English letters.

Example:

7
5 aabab
5 aabba
5 abbba
3 abb
4 aabc
6 aaabbb
6 aaaabb

outputFormat

For each test case, output a single line containing YES if it is possible to rearrange the string to have exactly \(n-2\) 'a's and exactly 2 'b's, otherwise output NO.

Example:

YES
YES
NO
YES
NO
NO
YES
## sample
2
3 abb
5 abbba
YES

NO

</p>