human
Distinct adjacent elements in a binary array | Python3 implementation of the above approach.
if array has only one element , return 1.
For first element compare with only next element.
For remaining elements compare with both prev and next elements.
For last element compare with only prev element.
Driver code"
Solution in Python:
 Write me a code to distinct adjacent elements in a binary array and the other steps required?
assistant
#Here is code to distinct adjacent elements in a binary array and the other steps required.
 def distinct ( arr ) :
	count = 0
	if len ( arr ) == 1 :
		return 1
	for i in range ( 0 , len ( arr ) - 1 ) :
		if ( i == 0 ) :
			if ( arr [ i ] != arr [ i + 1 ] ) :
				count += 1
		elif ( i > 0 & i < len ( arr ) - 1 ) :
			if ( arr [ i ] != arr [ i + 1 ] or arr [ i ] != arr [ i - 1 ] ) :
				count += 1
	if ( arr [ len ( arr ) - 1 ] != arr [ len ( arr ) - 2 ] ) :
		count += 1
	return count
arr = [ 0 , 0 , 0 , 0 , 0 , 1 , 0 ]
print ( distinct ( arr ) )