Problem title
Difficulty
Avg time to solve

Rearrange Array
Easy
15 mins
Find the Winner
Easy
10 mins
Custom Sort String
Easy
10 mins
Battalions and tanks
Moderate
10 mins
Mirror String
Easy
15 mins
Find the K-th Smallest Element in Array
Easy
10 mins
Median of a row wise sorted matrix
Moderate
30 mins
Minimum Number Of Swaps For Bracket Balancing
Moderate
15 mins
Minimum Rotations
Easy
10 mins
Rotate DLL
Moderate
10 mins
1

# Most Frequent Element

Difficulty: EASY
Contributed By

Problem Statement

#### 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
``````
##### Sample Input 1 :
``````2
brutegroot
codingninjas
``````
##### Sample Output 1 :
``````o
n
``````
##### Explanation For Sample Input 1 :
``````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.
``````
##### Sample Input 2 :
``````2
most
frequent
``````
##### Sample Output 2 :
``````m
e
``````
Console