6. Given a string of 2021 letters A and B. Consider the longest palindromic substring. What is its minimum possible length? A palindrome is a string that reads the same from right to left and from left to right.
Solution. The minimum possible length of the maximum palindrome is 4.

We will prove that it cannot be less than 4. Consider the 5 letters in the center of the string. If these are alternating letters, then it is a palindrome of length 5. Suppose among these five letters there are two identical letters standing next to each other. Take the maximal contiguous block of identical letters. It is at least 2 in length, and adding one opposite letter on each side, we get 4 (if there are no other letters on the sides, then we have reached the end of the string and there are many identical letters in a row, since we started from the center of the string).

Let's provide an example of a string where the maximum palindrome has a length of 4. This is a string where the sequence ABABAB repeats periodically: ABABABABABABABABABAB.... By checking all possible positions of the centers of palindromes, one can verify that there are no palindromes longer than 4 in this string. Due to the periodicity of the string, only a small number of cases need to be checked.

Comments. The specified example is unique up to shift and reflection.