human
Minimum number of colors required to color a Circular Array | Function that finds minimum number of colors required.
To check that if all the elements are same or not.
To check if only one adjacent exist.
Traverse the array.
If adjacent elements found different means all are not same.
If two adjacent elements found to be same then make one_adjacent_same true.
If all elements are same then print 1.
If total number of elements are even or there exist two adjacent elements that are same then print 2.
Else 3 type of colors are required.
Driver Code.
Function call"
Solution in Python:
assistant
#Here is code to minimum number of colors required to color a Circular Array and the other steps required.
 def colorRequired ( arr , n ) :
	all_same = True
	one_adjacent_same = False
	for i in range ( n - 1 ) :
		if ( arr [ i ] != arr [ i + 1 ] ) :
			all_same = False
		if ( arr [ i ] == arr [ i + 1 ] ) :
			one_adjacent_same = True
	if ( all_same == True ) :
		print ( 1 )
		return
	if ( n % 2 == 0 or one_adjacent_same == True ) :
		print ( 2 )
		return
	print ( 3 )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 1 , 1 , 2 ]
	n = len ( arr )
	colorRequired ( arr , n )