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
def oddOneOut ( arr , N ) : NEW_LINE INDENT odd = 0 NEW_LINE even = 0 NEW_LINE lastOdd = 0 NEW_LINE lastEven = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT even += 1 NEW_LINE lastEven = i NEW_LINE DEDENT else : NEW_LINE INDENT odd += 1 NEW_LINE lastOdd = i NEW_LINE DEDENT DEDENT if ( odd == 1 ) : NEW_LINE INDENT print ( lastOdd ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( lastEven ) NEW_LINE DEDENT DEDENT arr = [ 2 , 4 , 7 , 8 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE oddOneOut ( arr , N ) NEW_LINE