Prompt
Find the one outlier in an array where all numbers are even or all are odd except one. Return the outlier. The array may contain negative numbers.
Solution
This is a partition-by-predicate problem: split the array by parity, and whichever side has exactly one element holds the outlier. Two filters and a length check — O(n) time, O(n) space, direct and hard to get wrong.
The optimization conversation is what earns points here. You don't need to scan the whole array to know the majority parity: the first three elements decide it — at most one of them is the outlier, so at least two share the majority parity. With that, a short-circuiting find for the minority parity gives O(n) time, O(1) space, with early exit. Offering that refinement after the simple version shows judgment: write the clear one, then improve if the interviewer cares.
The actual trap is negative numbers and %. In JavaScript, % is a remainder that takes the sign of the dividend: -3 % 2 is -1, not 1. So the check n % 2 === 1 silently misclassifies every negative odd number. The safe forms are n % 2 !== 0 for odd (as here), n % 2 === 0 for even, or Math.abs(n) % 2. This single operator detail is why the prompt mentions negatives.
Red flag: n % 2 === 1 as the odd test — it returns false for -3, and the bug only appears with negative input, i.e., exactly the test case you didn't write. Say the remainder-vs-modulo distinction out loud.
Say it: "I partition by parity and return the singleton side — testing odd as n % 2 !== 0, because JS remainder is negative for negative dividends, so === 1 breaks on negatives."