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.

Description
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 and 1,000,000,000
JAVASCRIPT
OUTPUT
Results will appear here.