human
Minimize cost to convert given string to a palindrome | Function to find the minimum cost to convert the into a palindrome.
Length of the string.
If iointer is in the second half.
Reverse the string.
Find the farthest index needed to change on left side.
Find the farthest index needed to change on right side.
Changing the variable to make palindrome.
min distance to travel to make palindrome.
Total cost.
Return the minimum cost.
Driver Code.
Given S.
Given pointer P.
Function Call"
How can the above be solved in Python?
 ... Give me a code to minimize cost to convert given string to a palindrome and the other steps required?
assistant
#Here is code to minimize cost to convert given string to a palindrome and the other steps required.
 def findMinCost ( strr , pos ) :
	n = len ( strr )
	if ( pos >= n / 2 ) :
		strr = strr [ : : - 1 ]
		pos = n - pos - 1
	left , right = pos , pos
	for i in range ( pos , - 1 , - 1 ) :
		if ( strr [ i ] != strr [ n - i - 1 ] ) :
			left = i
	for i in range ( pos , n // 2 ) :
		if ( strr [ i ] != strr [ n - i - 1 ] ) :
			right = i
	ans = 0
	for i in range ( left , right + 1 ) :
		if ( strr [ i ] != strr [ n - i - 1 ] ) :
			ans += 1
	dis = ( min ( ( 2 * ( pos - left ) + ( right - pos ) ) , ( 2 * ( right - pos ) + ( pos - left ) ) ) )
	ans = ans + dis
	return ans
if __name__ == ' _ _ main _ _ ' :
	S = " bass "
	P = 3
	print ( findMinCost ( S , P ) )