

Ninja’s Friend came up again with a new challenge to test Ninja’s intelligence. There is a string ‘S’ consisting of ‘N’ small letters. Ninja’s task is to tell whether it is possible to rearrange the string so that it becomes palindromic. Can you help Ninja to solve this problem?
A string is said to be palindrome if it reads the same backward as forward. For example: naman, rotor, etc.
For ExampleIf N=5 and given string S is “rtoor”, the string can be rearranged as “rotor,” which is palindromic.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N’, denoting the length of the given string.
The second line contains the given string ‘S’.
Output Format:
For each test case, print ‘YES’ if the string can be rearranged into a palindromic string, else print ‘NO’.
Print the output of each test case in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^6.
S consists of only lowercase alphabets.
Time limit: 1 sec
2
5
rtoor
3
arm
YES
NO
For the first test case,
The given string can be rearranged as “rotor,” which is a palindromic string.
Hence, the answer is YES.
For the second test case:
The given string cannot be rearranged as a palindromic string
Hence, the answer is NO.
2
15
acabeececbeedad
10
ccdecaeeba
NO
NO
Check the frequency of each character.
In this approach, we will iterate through the whole string and store the frequency of each character. As we know, a palindromic string can have at most one character with an odd frequency. So, we will count the number of characters with odd frequencies, and if the count is greater than 1, the palindromic rearrangement is impossible. Else, palindromic rearrangement is possible.
Algorithm:
O(N), where ‘N’ is the length of string ‘S’.
In this approach, we are traversing the whole string ‘S’ to count the frequency of each character, which takes O(N) operations. Hence, the overall time complexity is O(N).
O(1)
In this approach, we store the frequency in the ‘FREQ’ array of size 26(constant space). Hence, the overall space complexity is O(1).