Find the unique number

jenny
انضم: 2025-08-24 15:11:06
2024-06-03 19:24:00

There is an array with some numbers. All numbers are equal except for one. Try to find it!

```
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 preview

blessedtechie
التحكم
انضم:
2024-06-03 23:06:43

Image preview

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.

jenny
انضم: 2025-08-24 15:11:06
2024-06-04 11:01:11

@"blessedtechie"#p284 this looks interesting, I need to study this closely

jenny
انضم: 2025-08-24 15:11:06
2024-07-25 10:38:40
[[9,31],[29]]
Facebook X (Twitter) Instagram LinkedIn Telegram WhatsApp