Minimum cost to convert string into palindrome | C # program to find minimum cost to make a palindrome . ; Function to return cost ; length of string ; Iterate from both sides of string . If not equal , a cost will be there ; Driver code
using System ; class GFG { static int cost ( String str ) { int len = str . Length ; int res = 0 ; for ( int i = 0 , j = len - 1 ; i < j ; i ++ , j -- ) if ( str [ i ] != str [ j ] ) res += Math . Min ( str [ i ] , str [ j ] ) - ' a ' + 1 ; return res ; } public static void Main ( ) { string str = " abcdef " ; Console . WriteLine ( cost ( str ) ) ; } }