human
What is a code to find index of the element differing in parity with all other array elements and the other steps required given the following:
Find index of the element differing in parity with all other array elements | Function to prthe element which differs in parity.
Stores the count of odd and even array elements encountered.
Stores the indices of the last odd and even array elements encountered.
Traverse the array.
If array element is even.
Otherwise.
If only one odd element is present in the array.
If only one even element is present in the array.
Given array.
Size of the array"
How can the above be solved in Python?
assistant
#Here is code to find index of the element differing in parity with all other array elements and the other steps required.
 def oddOneOut ( arr , N ) :
	odd = 0
	even = 0
	lastOdd = 0
	lastEven = 0
	for i in range ( N ) :
		if ( arr [ i ] % 2 == 0 ) :
			even += 1
			lastEven = i
		else :
			odd += 1
			lastOdd = i
	if ( odd == 1 ) :
		print ( lastOdd )
	else :
		print ( lastEven )
arr = [ 2 , 4 , 7 , 8 , 10 ]
N = len ( arr )
oddOneOut ( arr , N )