Find the farthest index needed to change on right side
for ( int i = pos ; i < n / 2 ; ++ i ) { if ( str [ i ] != str [ n - i - 1 ] ) { right = i ; } } int ans = 0 ; for ( int i = left ; i <= right ; ++ i ) {