Count minimum swap to make string palindrome | C # program to Count minimum swap to make string palindrome ; Function to Count minimum swap ; Length of string ; Counter to count minimum swap ; A loop which run in half string from starting ; Left pointer ; Right pointer ; A loop which run from right pointer to left pointer ; if both char same then break the loop if not same then we have to move right pointer to one step left ; it denotes both pointer at same position and we don 't  have sufficient char to make  palindrome string ; Driver Code ; Function calling
using System ; class GFG { static int countSwap ( String str ) { char [ ] s = str . ToCharArray ( ) ; int n = str . Length ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int left = i ; int right = n - left - 1 ; while ( left < right ) { if ( s [ left ] == s [ right ] ) { break ; } else { right -- ; } } if ( left == right ) { return - 1 ; } else { for ( int j = right ; j < n - left - 1 ; j ++ ) { char t = s [ j ] ; s [ j ] = s [ j + 1 ] ; s [ j + 1 ] = t ; count ++ ; } } } return count ; } public static void Main ( String [ ] args ) { String s = " geeksfgeeks " ; int ans1 = countSwap ( s ) ; char [ ] charArray = s . ToCharArray ( ) ; Array . Reverse ( charArray ) ; s = new string ( charArray ) ; int ans2 = countSwap ( s ) ; if ( ans1 > ans2 ) Console . WriteLine ( ans1 ) ; else Console . WriteLine ( ans2 ) ; } }