Maximize count of 3 | Function to count the maximum number oaf palindrome subsequences of length 3 considering the same index only once ; Index of the string S ; Stores the frequency of every character ; Stores the pair of frequency containing same characters ; Number of subsequences having length 3 ; Counts the frequency ; Counts the pair of frequency ; Returns the minimum value ; Driver Code
function maxNumPalindrome ( S ) { let i = 0 ; let freq = new Array ( 26 ) . fill ( 0 ) ; let freqPair = 0 ; let len = ( S . length / 3 ) ; while ( i < S . length ) { freq [ S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; i ++ ; } for ( i = 0 ; i < 26 ; i ++ ) { freqPair += Math . floor ( freq [ i ] / 2 ) ; } return Math . min ( freqPair , len ) ; } let S = " " ; document . write ( maxNumPalindrome ( S ) + " " ) ;