Return maximum occurring character in an input string | Python program to return the maximum occurring character in the input string ; Create array to keep the count of individual characters Initialize the count array to zero ; Construct character count array from the input string . ; Initialize max count ; Initialize result ; Traversing through the string and maintaining the count of each character ; Driver program to test the above function
ASCII_SIZE = 256 NEW_LINE def getMaxOccuringChar ( str ) : NEW_LINE INDENT count = [ 0 ] * ASCII_SIZE NEW_LINE for i in str : NEW_LINE INDENT count [ ord ( i ) ] += 1 ; NEW_LINE DEDENT max = - 1 NEW_LINE c = ' ' NEW_LINE for i in str : NEW_LINE INDENT if max < count [ ord ( i ) ] : NEW_LINE INDENT max = count [ ord ( i ) ] NEW_LINE c = i NEW_LINE DEDENT DEDENT return c NEW_LINE DEDENT str = " sample ▁ string " NEW_LINE print " Max ▁ occurring ▁ character ▁ is ▁ " + getMaxOccuringChar ( str ) NEW_LINE