Maximum repeating character for every index in given String | Function to print the maximum repeating character at each index of the String ; Stores frequency of each distinct character ; Stores frequency of maximum repeating character ; Stores the character having maximum frequency ; Traverse the String ; Stores current character ; Update the frequency of str [ i ] ; If frequency of current character exceeds max ; Update max ; Update charMax ; Print the required output ; Driver Code ; Stores length of str
function findFreq ( str , N ) { let freq = new Array ( 256 ) . fill ( 0 ) ; let max = 0 ; let charMax = ' ' ; for ( let i = 0 ; i < N ; i ++ ) { let ch = str [ i ] . charCodeAt ( 0 ) ; freq [ ch ] ++ ; if ( freq [ ch ] >= max ) { max = freq [ ch ] ; charMax = ch ; } document . write ( String . fromCharCode ( charMax ) + " " + max + " " ) ; } } let str = " " ; let N = str . length ; findFreq ( str , N ) ;