human
Smallest length string with repeated replacement of two distinct adjacent | Returns smallest possible length with given operation allowed ..
Counint occurrences of three different characters ' a ' , ' b ' and ' c ' in str.
If all characters are same ..
If all characters are present even number of times or all are present odd number of times ..
Answer is 1 for all other cases ..
Driver code"
How can the above be solved in Python?
 ... Write me a code to smallest length string with repeated replacement of two distinct adjacent and the other steps required?
assistant
#Here is code to smallest length string with repeated replacement of two distinct adjacent and the other steps required.
 def stringReduction ( str ) :
	n = len ( str )
	count = [ 0 ] * 3
	for i in range ( n ) :
		count [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1
	if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :
		return n
	if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :
		return 2
	return 1
if __name__ == " _ _ main _ _ " :
	str = " abcbbaacb "
	print ( stringReduction ( str ) )