πŸ’¬ Debugging & Tutorials

Find the unique number

d

diltony@yahoo.com

Jan 2, 2026 at 2:56 PM

β€’ 3 replies β€’ 233 views
There is an array with some numbers. All numbers are equal except for one. Try to find it!

[s]```[/s]
findUniq([ 1, 1, 1, 2, 1, 1 ]) === 2
findUniq([ 0, 0, 0.55, 0, 0 ]) === 0.55
```
It’s guaranteed that array contains at least 3 numbers.

The tests contain some very huge arrays, so think about performance.

Image

3 Replies

Sign in to join the conversation

b

blessing@africoders.com

5 days ago
Image

The first step uses conditional checks to identify which of the first three elements is the common number.
The second step iterates through the array and returns the first element that does not match the common number.
This method is efficient because it uses a fixed number of checks to determine the common number and then a linear scan to find the unique number, ensuring it performs well even with large arrays.
d

diltony@yahoo.com

5 days ago
@"blessedtechie"#p284 this looks interesting, I need to study this closely
d

diltony@yahoo.com

5 days ago
[[9,31],[29]]