human
Write me a code to number of Counterclockwise shifts to make a string palindrome and the other steps required given the following:
Number of Counterclockwise shifts to make a string palindrome | Function to check if given string is palindrome or not ..
Function to find counter clockwise shifts to make string palindrome ..
Pointer to starting of current shifted string ..
Pointer to ending of current shifted string ..
Concatenate string with itself.
To store counterclockwise shifts.
Move left and right pointers one step at a time ..
Check if current shifted string is palindrome or not.
If string is not palindrome then increase count of number of shifts by 1..
Driver code ."
Solution in Python:
assistant
#Here is code to number of Counterclockwise shifts to make a string palindrome and the other steps required.
 def isPalindrome ( str , l , r ) :
	while ( l < r ) :
		if ( str [ l ] != str [ r ] ) :
			return False
		l += 1
		r -= 1
	return True
def CyclicShifts ( str ) :
	n = len ( str )
	left = 0
	right = n - 1
	str = str + str
	cnt = 0
	while ( right < 2 * n - 1 ) :
		if ( isPalindrome ( str , left , right ) ) :
			break
		cnt += 1
		left += 1
		right += 1
	return cnt
if __name__ == " _ _ main _ _ " :
	str = " bccbbaab " ;
	print ( CyclicShifts ( str ) )