#325 Finding the Number Without a Pair in an Array
An array contains numbers where every number except one has a pair, meaning it occurs twice. Find the number that occurs only once:
// <= [1, 0, 3, -2, 9, 9, 1, -2, 0]
// => 3
int find(int[] arr) {
...
}
Additional conditions:
-
nullor an empty array -> throwRuntimeException. -
More than one number without a pair -> throw
RuntimeException. -
No number occurs exactly once -> throw
RuntimeException. -
Any number occurs more than twice -> throw
RuntimeException.
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor