Frequency of maximum occurring subsequence in given string | Function to find the frequency ; freq stores frequency of each english lowercase character ; dp [ i ] [ j ] stores the count of subsequence with ' a ' + i and ' a ' + j character ; Increment the count of subsequence j and s [ i ] ; Update the frequency array ; For 1 length subsequence ; For 2 length subsequence ; Return the final result ; Given string str ; Function Call
function findCount ( s ) { var freq = Array ( 26 ) . fill ( 0 ) ; var dp = Array . from ( Array ( 26 ) , ( ) => Array ( 26 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < s . length ; ++ i ) { for ( var j = 0 ; j < 26 ; j ++ ) { dp [ j ] [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += freq [ j ] ; } freq [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } var ans = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) ans = Math . max ( freq [ i ] , ans ) ; for ( var i = 0 ; i < 26 ; i ++ ) { for ( var j = 0 ; j < 26 ; j ++ ) { ans = Math . max ( dp [ i ] [ j ] , ans ) ; } } return ans ; } var str = " " ; document . write ( findCount ( str ) ) ;