Answer:
The function in Python, is as follows:
def maximumOccurringCharacter(mystring):
kount = [0] * 256
maxKount = -1
chr = ''
for i in mystring:
kount[ord(i)]+=1;
for i in mystring:
if maxKount < kount[ord(i)]:
maxKount = kount[ord(i)]
chr = i
return chr
Explanation:
This defines the function
def maximumOccurringCharacter(mystring):
This creates a list of 256 characters (the number of ascii characters); the list is then initialized to 0
kount = [0] * 256
This initializes the maximum count to -1
maxKount = -1
This initializes the string with maximum number of occurrence to an empty character
chr = ''
This iterates through the string and gets the occurrence of each character
for i in mystring:
kount[ord(i)]+=1;
This iterates through the string, compares the occurrence of each string with maxKount and return the character with the highest
<em> for i in mystring:
</em>
<em> if maxKount < kount[ord(i)]:
</em>
<em> maxKount = kount[ord(i)]
</em>
<em> chr = i
</em>
<em> return chr</em>