human
Find index of the element differing in parity with all other array elements | Function to print the array element which differs in parity with the remaining array elements.
Multimaps to store even and odd numbers along with their indices.
Traverse the array.
If array element is even.
Otherwise.
If only one even element is present in the array.
If only one odd element is present in the array.
.
Given array.
Size of the array"
Solution 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 ) :
	e , o = { } , { }
	for i in range ( N ) :
		if ( arr [ i ] % 2 == 0 ) :
			e [ arr [ i ] ] = i
		else :
			o [ arr [ i ] ] = i
	if ( len ( e ) == 1 ) :
		print ( list ( e . values ( ) ) [ 0 ] )
	else :
		print ( list ( o . values ( ) ) [ 0 ] )
/ * Driver Code * /
arr = [ 2 , 4 , 7 , 8 , 10 ]
N = len ( arr )
OddOneOut ( arr , N )