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