Given an alphabetical string ‘S’. Return the most frequent character of ‘S’. If there are multiple characters with the same frequency equal to the maximal frequency, return the lexicographically smallest character with maximal frequency.
For example:‘S’ = brutegroot
The most frequent characters are [o, r, t]. All of these characters appear 2 times each.
As among all the options, ‘o’ is lexicographically smallest. So the answer is ‘o’.
Hence output will be o.
Input Format:
The first line of the input contains a single integer ‘T’ representing the no. of test cases.
The first line of each test case contains a single alphabetical string, ‘S’.
Output Format:
For each test case, print a single character representing the most frequent character of the given string.
Print a separate line for each test case.
Note:
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
Constraints:
1 ≤ T ≤ 1000
1 ≤ |S| ≤ 10^5
S consists of only lowercase english alphabets.
Σ|S| ≤ 2 * 10^6
Time limit: 1 Sec
2
brutegroot
codingninjas
o
n
For First Case - Same as explained in above example.
For the second case -
‘S’ = codingninjas
‘n’ appears the most number of times, i.e., 3. So the answer will be ‘n’.
Hence output will be n.
2
most
frequent
m
e