Single Lonely Number (Easy)
Good morning! Here's our prompt for today.
You may see this problem at Google, Flipkart, Twitter, Vmware, Adobe, Wework, Ebay, Groupon, Tableau Software, Workday, Jane Street, Servicetitan, Squarespace, Keeptruckin, Zoom, Tradeshift, Baidu, New Relic, and Qualtrics.
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
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');
OUTPUT
Results will appear here.