human
Minimum operations required to modify the array such that parity of adjacent elements is different | Function to return the parity of a number.
Function to return the minimum number of operations required.
Operation needs to be performed.
Parity of previous element.
Parity of next element.
Update parity of current element to be other than the parities of the previous and the next number.
Driver Code"
Solution in Python:
 Write me a code to minimum operations required to modify the array such that parity of adjacent elements is different and the other steps required?
assistant
#Here is code to minimum operations required to modify the array such that parity of adjacent elements is different and the other steps required.
 def parity ( a ) :
	return a % 3
def solve ( array , size ) :
	operations = 0
	for i in range ( 0 , size - 1 ) :
		if parity ( array [ i ] ) == parity ( array [ i + 1 ] ) :
			operations += 1
			if i + 2 < size :
				pari1 = parity ( array [ i ] )
				pari2 = parity ( array [ i + 2 ] )
				if pari1 == pari2 :
					if pari1 == 0 :
						array [ i + 1 ] = 1
					elif pari1 == 1 :
						array [ i + 1 ] = 0
					else :
						array [ i + 1 ] = 1
				else :
					if ( ( pari1 == 0 and pari2 == 1 ) or ( pari1 == 1 and pari2 == 0 ) ) :
						array [ i + 1 ] = 2
					if ( ( pari1 == 1 and pari2 == 2 ) or ( pari1 == 2 and pari2 == 1 ) ) :
						array [ i + 1 ] = 0
					if ( ( pari1 == 2 and pari2 == 0 ) and ( pari1 == 0 and pari2 == 2 ) ) :
						array [ i + 1 ] = 1
	return operations
if __name__ == " _ _ main _ _ " :
	array = [ 2 , 1 , 3 , 0 ]
	size = len ( array )
	print ( solve ( array , size ) )