Count maximum occurrence of subsequence in string such that indices in subsequence is in A . P . | Function to find the maximum occurrence of the subsequence such that the indices of characters are in arithmetic progression ; Frequencies of subsequence ; Loop to find the frequencies of subsequence of length 1 ; Loop to find the frequencies subsequence of length 2 ; Finding maximum frequency ; Driver Code
function maximumOccurrence ( s ) { var n = s . length ; var freq = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { var temp = " " ; temp += s [ i ] ; if ( freq . has ( temp ) ) freq . set ( temp , freq . get ( temp ) + 1 ) else freq . set ( temp , 1 ) } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { var temp = " " ; temp += s [ i ] ; temp += s [ j ] ; if ( freq . has ( temp ) ) freq . set ( temp , freq . get ( temp ) + 1 ) else freq . set ( temp , 1 ) } } var answer = - 1000000000 ; freq . forEach ( ( value , key ) => { answer = Math . max ( answer , value ) ; } ) ; return answer ; } var s = " " ; document . write ( maximumOccurrence ( s ) ) ;