Cody

# Problem 1237. It's race time! Write a faster function than the test suite call of unique().

Solution 2231023

Submitted on 23 Apr 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = rand(10000, 1); z = rand(10000, 1); x = vertcat(x, z); tic y_correct = unique(x); t_unique = toc tic y_myunique = my_unique(x); t_myunique = toc assert(isequal(sort(my_unique(x)),y_correct) && t_unique > t_myunique)

t_unique = 0.0128 Elapsed time is 0.009816 seconds. Elapsed time is 0.000026 seconds. t_myunique = 6.0000e-05 Elapsed time is 0.001912 seconds. Elapsed time is 0.000025 seconds.

2   Pass
x = rand(50000, 1); z = rand(50000, 1); x = vertcat(x, z); tic y_correct = unique(x); t_unique = toc tic y_my_unique = my_unique(x); t_my_unique = toc assert(isequal(sort(my_unique(x)),y_correct) && t_unique > t_my_unique)

t_unique = 0.0146 Elapsed time is 0.012435 seconds. Elapsed time is 0.000027 seconds. t_my_unique = 6.5000e-05 Elapsed time is 0.021626 seconds. Elapsed time is 0.000019 seconds.

3   Fail
x = [1; 2; 3; 4; 2; 3; 4; 5;]; tic y_correct = unique(x); t_unique = toc tic y_my_unique = my_unique(x); t_my_unique = toc assert(isequal(sort(my_unique(x)),y_correct) && t_unique > t_my_unique)

t_unique = 2.4900e-04 Elapsed time is 0.000714 seconds. Elapsed time is 0.000101 seconds. t_my_unique = 3.6700e-04 Elapsed time is 0.000748 seconds. Elapsed time is 0.000008 seconds.

Assertion failed.