6 kyu

Find the unique number

52,694 of 149,652isqua

Description:

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
findUniq([ 1, 1, 1, 2, 1, 1 ]) == 2
findUniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2
find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2
find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55
Kata.findUniq(new double[]{ 1, 1, 1, 2, 1, 1 }); // => 2
Kata.findUniq(new double[]{ 0, 0, 0.55, 0, 0 }); // => 0.55
getUnique [1, 1, 1, 2, 1, 1] -- Result is 2
getUnique [0, 0, 0.55, 0, 0] -- Result is 0.55
findUniq([ 1; 1; 1; 2; 1; 1 ]) = 2
findUniq([ 0; 0; 0.55; 0; 0 ]) = 0.55
finduniq((const float[]){1, 1, 1, 2, 1, 1}, 5); /* --> 2 */
finduniq((const float[]){0, 0, 0.55, 0, 0}, 5); /* --> 0.55 */
nums:  dd  1., 1., 1., 2., 1., 1.

mov rdi, nums
mov rsi, 6
call finduniq       ; XMM0 <- 2


nums:   dd  0., 0., 0.55, 0., 0.

mov rdi, nums
mov rsi, 6
call finduniq       ; XMM0 <- 0.55
find_uniq(std::vector<float>{1, 1, 1, 2, 1, 1});  // --> 2
find_uniq(std::vector<float>{0, 0, 0.55, 0, 0});  // --> 0.55
find_uniq(&[1.0, 1.0, 1.0, 2.0, 1.0, 1.0]) // => 2.0
find_uniq(&[0.0, 0.0, 0.55, 0.0, 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.

This is the first kata in series:

  1. Find the unique number (this kata)
  2. Find the unique string
  3. Find The Unique
Fundamentals
Algorithms
Arrays
Performance

Stats:

CreatedDec 23, 2016
PublishedDec 23, 2016
Warriors Trained234830
Total Skips27688
Total Code Submissions672570
Total Times Completed149652
JavaScript Completions52694
PHP Completions3279
Python Completions56664
Java Completions16359
TypeScript Completions3359
Go Completions3070
C# Completions7702
Haskell Completions1008
Ruby Completions2875
F# Completions73
Swift Completions796
COBOL Completions17
D Completions10
C Completions1252
NASM Completions15
C++ Completions2699
Rust Completions148
Total Stars2856
% of votes with a positive feedback rating90% of 10942
Total "Very Satisfied" Votes9036
Total "Somewhat Satisfied" Votes1697
Total "Not Satisfied" Votes209
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • isqua Avatar
  • Unnamed Avatar
  • raulbc777 Avatar
  • user8476848 Avatar
  • donaldsebleung Avatar
  • hnefatl Avatar
  • Chrono79 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • ArcaneIntegers Avatar
  • JohanWiltink Avatar
  • JorgeVS Avatar
  • Blind4Basics Avatar
  • Firefly2002 Avatar
  • idzmitry Avatar
  • Voile Avatar
  • Madjosz Avatar
  • neilm Avatar
  • Awesome A.D. Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • uniapi Avatar
  • Wargrave Avatar
  • akar-0 Avatar
  • pastre Avatar
  • farhanaditya Avatar
  • estem8 Avatar
Ad