Maximum number of characters between any two same character in a string | Simple Javascript program to find maximum number of characters between two occurrences of same character ; Driver code
function maximumChars ( str ) { let n = str . length ; let res = - 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) res = Math . max ( res , Math . abs ( j - i - 1 ) ) ; return res ; } let str = " " ; document . write ( maximumChars ( str ) ) ;