In principle (subject to edge case below), how about:
def find_outlier(integers):
remainder = integers[0] % 2
for i in integers:
if i % 2 != remainder:
return i
This will, however, not handle the edge case where the outlier is the first item in the array. So...
def find_outlier(integers):
test = integers[0:3]
triple = sum(map(lambda x: x % 2, test))
if triple % 3: # outlier in first 3
remainder = 1 - triple % 2
else:
remainder = triple % 2
test = integers[3:]
for i in test:
if i % 2 != remainder:
return i
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In principle (subject to edge case below), how about:
This will, however, not handle the edge case where the outlier is the first item in the array. So...