Mark As Completed Discussion

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.

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

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
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.

Returning members can login to stop seeing this.