Company: trading tech_17sep
Difficulty: medium
Maximum Three-Letter Palindromes Problem Description A string is a palindrome if it reads the same backward as forward. For example, "madam" and "racecar" are palindromes, but "milk" is not. Write a function: def solution(S) that, given a string S made of N letters, returns the maximum number of three-letter palindromes you can build using letters from S. You can use each letter from S once. Examples Example 1: Input: S = "aaaabc" Output: 2 Explanation: Examples of three-letter palindromes you can build simultaneously are "aba" and "aca". Example 2: Input: S = "xyvzwy" Output: 1 Example 3: Input: S = "dd" Output: 0 Explanation: You cannot build any three-letter palindrome. Example 4: Input: S = "fknfkn" Output: 2 Constraints Write an efficient algorithm for the following assumptions: N is an integer within the range [1..50,000]; string S is made only of lowercase letters (a-z).