Maximize count of 3 | Function to count the maximum number of palindrome subsequences of length 3 considering the same index only once ; Index of the 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
def maxNumPalindrome ( S ) : NEW_LINE INDENT i = 0 NEW_LINE freq = [ 0 ] * 26 NEW_LINE freqPair = 0 NEW_LINE ln = len ( S ) // 3 NEW_LINE while ( i < len ( S ) ) : NEW_LINE INDENT freq [ ord ( S [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE i += 1 NEW_LINE DEDENT for i in range ( 26 ) : NEW_LINE INDENT freqPair += ( freq [ i ] // 2 ) NEW_LINE DEDENT return min ( freqPair , ln ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " geeksforg " NEW_LINE print ( maxNumPalindrome ( S ) ) NEW_LINE DEDENT