You are given an array with N numbers. N - 1 numbers are the same. You must find the unique number.
The input array will always have at least 3 numbers.
The input array can be very large. Be mindful of performance.
DO NOT USE GOOGLE!!!
DO NOT LOOK AT OTHER SUBMISSIONS!!!
DO NOT EDIT THE TEST CASES!!!
findUniqueNumber([ 1; 1; 1; 2; 1; 1 ]) = 2
findUniqueNumber([ 0; 0; 0.55; 0; 0 ]) = 0.55
module ExampleSolution
let findUniqueNumber array =
() // your code goes here
module ExampleTests
open ExampleSolution
// NUnit is used to test F# 6.0.
open NUnit.Framework
[<Test()>]
[<TestCase(0,[| 0; 1; 1; 1; 1; 1; 1; 1 |])>]
[<TestCase(1,[| 2; 2; 2; 2; 2; 2; 2; 1 |])>]
[<TestCase(2,[| 3; 3; 3; 3; 3; 3; 3; 2 |])>]
[<TestCase(3,[| 4; 4; 4; 3; 4; 4; 4; 4 |])>]
[<TestCase(4,[| 5; 5; 5; 5; 4; 5; 5; 5 |])>]
[<TestCase(5,[| 6; 6; 6; 6; 6; 5; 6; 6 |])>]
[<TestCase(6,[| 7; 7; 7; 7; 7; 7; 6; 7 |])>]
[<TestCase(7,[| 8; 8; 8; 8; 8; 8; 8; 7 |])>]
[<TestCase(1.56,[| 0.55; 0.55; 1.56; 0.55; 0.55 |])>]
[<TestCase(1,[| 2; 1; 2; |])>]
let TestShortArray (x,y) =
Assert.AreEqual(x, findUniqueNumber y)
let generateTestArray length characterToFillWith uniqueNumber =
let testArray = Array.replicate length characterToFillWith
testArray.[System.Random().Next(0, length)] <- uniqueNumber
testArray
[<Test(ExpectedResult=2)>]
let TestOneThousandIntegers () =
findUniqueNumber (generateTestArray 1000 1 2)
[<Test(ExpectedResult=5)>]
let TestOneMillionIntegers () =
findUniqueNumber (generateTestArray 1000000 1 5)
[<Test(ExpectedResult=0.5)>]
let TestOneThousandFloats () =
findUniqueNumber (generateTestArray 1000 0.1 0.5)
[<Test(ExpectedResult=0.2)>]
let TestOneMillionFloats () =
findUniqueNumber (generateTestArray 1000000 0.1 0.2)
You are given an array with N numbers. N - 1 numbers are the same. You must find the unique number.
- The input array will always have at least 3 numbers.
- The input array can be very large. Be mindful of performance.
DO NOT USE GOOGLE!!!
DO NOT LOOK AT OTHER SUBMISSIONS!!!
DO NOT EDIT THE TEST CASES!!!
findUniqueNumber([ 1; 1; 1; 2; 1; 1 ]) = 2
findUniqueNumber([ 0; 0; 0.55; 0; 0 ]) = 0.55
You are given an array with N numbers. N - 1 numbers are the same. You must find the unique number.
- The input array will always have at least 3 numbers.
- The input array can be very large. Be mindful of performance.
NOTES:
- NO GOOGLE ALLOWED!!!!!
- DO NOT LOOK AT OTHER SUBMISSIONS!!!
findUniqueNumber([ 1; 1; 1; 2; 1; 1 ]) = 2
findUniqueNumber([ 0; 0; 0.55; 0; 0 ]) = 0.55
module ExampleSolution
let findUniqueNumber array =
()
module ExampleTests
open ExampleSolution
// NUnit is used to test F# 6.0.
open NUnit.Framework
[<Test()>]
[<TestCase(0,[| 0; 1; 1; 1; 1; 1; 1; 1 |])>]
[<TestCase(1,[| 2; 2; 2; 2; 2; 2; 2; 1 |])>]
[<TestCase(2,[| 3; 3; 3; 3; 3; 3; 3; 2 |])>]
[<TestCase(3,[| 4; 4; 4; 3; 4; 4; 4; 4 |])>]
[<TestCase(4,[| 5; 5; 5; 5; 4; 5; 5; 5 |])>]
[<TestCase(5,[| 6; 6; 6; 6; 6; 5; 6; 6 |])>]
[<TestCase(6,[| 7; 7; 7; 7; 7; 7; 6; 7 |])>]
[<TestCase(7,[| 8; 8; 8; 8; 8; 8; 8; 7 |])>]
[<TestCase(1.56,[| 0.55; 0.55; 1.56; 0.55; 0.55 |])>]
[<TestCase(1,[| 2; 1; 2; |])>]
let TestShortArray (x,y) =
Assert.AreEqual(x, findUniqueNumber y)
let generateTestArray length characterToFillWith uniqueNumber =
let testArray = Array.replicate length characterToFillWith
testArray.[System.Random().Next(0, length)] <- uniqueNumber
testArray
[<Test(ExpectedResult=2)>]
let TestOneThousandIntegers () =
findUniqueNumber (generateTestArray 1000 1 2)
[<Test(ExpectedResult=5)>]
let TestOneMillionIntegers () =
findUniqueNumber (generateTestArray 1000000 1 5)
[<Test(ExpectedResult=0.5)>]
let TestOneThousandFloats () =
findUniqueNumber (generateTestArray 1000 0.1 0.5)
[<Test(ExpectedResult=0.2)>]
let TestOneMillionFloats () =
findUniqueNumber (generateTestArray 1000000 0.1 0.2)
add 2 numbers
module ExampleSolution
let add a b = a + b
module ExampleTests
open ExampleSolution
// NUnit is used to test F# 6.0.
open NUnit.Framework
[<Test>]
let TestAdd() =
Assert.AreEqual(2, add 1 1)
[<TestFixture>]
type FixedTests() =
[<Test>]
member this.TestOne() =
Assert.AreEqual(1, add 0 1)