Good evening! Here's our prompt for today.
In a given array of numbers, one element will show up once and the others will each show up twice. Can you find the number that only appears once in O(n)
linear time? Bonus points if you can do it in O(1)
space as well.

SNIPPET
1lonelyNumber([4, 4, 6, 1, 3, 1, 3])
2// 6
3
4lonelyNumber([3, 3, 9])
5// 9
Constraints
- Length of the array <=
100,000
- The values of the array will be between
-1,000,000,000
and1,000,000,000
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
45
var assert = require('assert');
​
function lonelyNumber(numbers) {
// Fill in this method
return numbers;
}
​
try {
assert.equal(lonelyNumber([4, 4, 6, 1, 3, 1, 3]), 6);
​
console.log(
'PASSED: ' + '`lonelyNumber([4, 4, 6, 1, 3, 1, 3])` should return `6`'
);
} catch (err) {
console.log(err);
}
​
try {
assert.equal(lonelyNumber([3, 3, 9]), 9);
​
console.log('PASSED: ' + '`lonelyNumber([3, 3, 9])` should return `9`');
} catch (err) {
console.log(err);
}
​
try {
assertIsFunction(lonelyNumber, '`lonelyNumber` is a function');
​
console.log('PASSED: ' + '`lonelyNumber` is a function');
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Tired of reading? Watch this video explanation!
To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

Here's our guided, illustrated walk-through.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.