You might be given an array (which can have a size of at the least 3, however might be very giant) containing integers. The array is both totally comprised of wierd integers or totally comprised of even integers aside from a single integer N. Write a way that takes the array as an argument and returns this “outlier” N.
Examples-
[2, 4, 0, 100, 4, 11, 2602, 36]
Ought to return: 11 (the one odd quantity)
[160, 3, 1719, 19, 11, 13, -21]
Ought to return: 160 (the one even quantity)
Pattern Exams
check.assert_equals(find_outlier([2, 4, 6, 8, 10, 3]), 3)
check.assert_equals(find_outlier([2, 4, 0, 100, 4, 11, 2602, 36]), 11)
check.assert_equals(find_outlier([160, 3, 1719, 19, 11, 13, -21]), 160)
Answer- ###Python
def find_outlier(integers):
even=[]
odd=[]
for i in integers:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
if len(even)==1:
return even[0]
else:
return odd[0]