Return maximum occurring character in an input string | Javascript program to output the maximum occurring character in a string ; Create array to keep the count of individual characters and initialize the array as 0 ; 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 Method
let ASCII_SIZE = 256 ; function getMaxOccuringChar ( str ) { let count = new Array ( ASCII_SIZE ) ; for ( let i = 0 ; i < ASCII_SIZE ; i ++ ) { count [ i ] = 0 ; } let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { count [ str [ i ] . charCodeAt ( 0 ) ] += 1 ; } let max = - 1 ; let result = ' ' ; for ( let i = 0 ; i < len ; i ++ ) { if ( max < count [ str [ i ] . charCodeAt ( 0 ) ] ) { max = count [ str [ i ] . charCodeAt ( 0 ) ] ; result = str [ i ] ; } } return result ; } let str = " " ; document . write ( " " , getMaxOccuringChar ( str ) ) ;