💬 Debugging & Tutorials

Find The Parity Outlier

d

diltony@yahoo.com

Jan 2, 2026 at 2:56 PM

3 replies 235 views
You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N.

Examples
[2, 4, 0, 100, 4, 11, 2602, 36] --> 11 (the only odd number)

[160, 3, 1719, 19, 11, 13, -21] --> 160 (the only even number)

Image

3 Replies

Sign in to join the conversation

b

blessing@africoders.com

6 days ago
Image

This problem brings back memories of a classic computer science homework: identifying the outlier in a list of numbers. Here's a clever solution that leverages the parity (even or odd) of the first few elements.

[*][s]1. [/s][s]**[/s]Parity Check:** We start by examining the parity of the first three numbers in the list. Even numbers result in a remainder of 0 when divided by 2, while odds yield a remainder of 1.

[*][s]2. [/s][s]**[/s]Majority Rules:** By storing these remainders in a list, we can determine the prevailing parity (even or odd) in the majority.

[*][s]3. [/s][s]**[/s]Find the Outlier:** Finally, we iterate through the entire list. The first number whose parity doesn't match the majority is our outlier!

This approach offers an efficient way to pinpoint the outlier, making it a valuable technique to have in your problem-solving toolbox.
d

diltony@yahoo.com

6 days ago
[[9,31],[29]]
d

diltony@yahoo.com

6 days ago
Outlier in an array is a very good interview question too, it will get you sweating a bit. No, did I say good? I meant terrible!