can anyone help me how to do this??

Find what range each palindromic pair can have in one turn. minimum is min(a, b)+1, and maximum is max(a, b) + k. Find the number of palindromes having sum x for all x between 2 and 2k. Now for each i between 2 and 2k, count the number of active segments. No. of active segments - the number of pairs that add up to i, Need 1 change, and n/2 - no. of active segments, need 2 changes.

1 Like