-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximum occuring character.py
More file actions
51 lines (33 loc) · 937 Bytes
/
Maximum occuring character.py
File metadata and controls
51 lines (33 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# User function Template for python3
class Solution:
# Function to find the maximum occurring character in a string.
def getMaxOccurringChar(self, s):
dic = {}
maxx = 0
for i in s:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
maxx = max(maxx, dic[i])
out = [char for char, freq in dic.items() if freq == maxx]
return min(out)
# {
# Driver Code Starts
# Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__ == "__main__":
t = int(input())
for i in range(t):
s = str(input())
print(Solution().getMaxOccurringChar(s))
# } Driver Code Ends