Maximum Occuring Character
Submissions: 5383   Accuracy:

35.78%

  Difficulty: Basic   Marks: 1
Associated Course(s):   Geeks Classes in Noida

Given a string str. The task is to find the maximum occurring character in the string str. If more than one character occurs maximum number of time then print the lexicographically smaller character.

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case consist of a string in 'lowercase' only in a separate line.

Output:
For each testcase, in a new line, print the lexicographically smaller character which occurred the maximum time.

Constraints:
1 ≤ T ≤ 30

1 ≤ |s| ≤ 100

Example:
Input:

2
testsample
output

Output:
e
t

Explanation:
Testcase 1:
e is the character which is having highest frequency.
Testcase 2: t and u are the characters with the same frequency, but t is lexicographically smaller.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: shef5


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.