human
Can you provide a code to smallest index such that there are no 0 or 1 to its right and the other steps required given the following:
Smallest index such that there are no 0 or 1 to its right | Function to find the smallest index such that there are no 0 or 1 to its right.
Initially.
Traverse in the array.
Check if array element is 1.
a [ i ] = 0.
Return minimum of both.
Driver code"
Solution in Python:
assistant
#Here is code to smallest index such that there are no 0 or 1 to its right and the other steps required.
 def smallestIndex ( a , n ) :
	right1 = 0
	right0 = 0
	for i in range ( n ) :
		if ( a [ i ] == 1 ) :
			right1 = i
		else :
			right0 = i
	return min ( right1 , right0 )
if __name__ == ' _ _ main _ _ ' :
	a = [ 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 ]
	n = len ( a )
	print ( smallestIndex ( a , n ) )