Finding the Unique Number

Nicholas
2 min readApr 8, 2021

As I am getting ready for interview I have been practicing algorithm problems and the problem that we will be dissecting is finding a unique number. This problem will give you an array of at least 3 numbers that with all of the numbers being the same except one element.

The first step I took was to define the item that i was going to put the unique number in when I found it, and that element was an array. I also created a new variable that will sort the array in ascending order so that it is more organized and easier to handle.

Now that we set all the variables needed now we can sort through the array to find the unique number in the array. The way that I sorted through the array was through a for loop, the way that I determined whether or not to push the element into theNumber array was if the element was not equal to the number before and after it, it would get pushed into theNumber array.

The final step was to call back theNumber array. I originally just called back the array but the element was not going through so I had to call back the only element in it.

--

--