Cody

# Problem 1985. How unique?

Solution 2026554

Submitted on 18 Nov 2019 at 15:36 by Doan Quang Manh
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
A = [2 2 2 3 3 2 3 8 6 5 6]; [U, H] = hunique(A); U_ok = [2 3 8 6 5]; H_ok = [4 3 1 2 1]; assert(isequal(U,U_ok)); assert(isequal(H,H_ok));

U = 2 U = 2 3 U = 2 3 8 U = 2 3 8 6 U = 2 3 8 6 5 H = 4 H = 4 3 H = 4 3 1 H = 4 3 1 2 H = 4 3 1 2 1

2   Pass
A = [2 2 2 3 3 2 3 8 6 5 6 8]; [U, H] = hunique(A); U_ok = [2 3 8 6 5]; H_ok = [4 3 2 2 1]; assert(isequal(U,U_ok)); assert(isequal(H,H_ok));

U = 2 U = 2 3 U = 2 3 8 U = 2 3 8 6 U = 2 3 8 6 5 H = 4 H = 4 3 H = 4 3 2 H = 4 3 2 2 H = 4 3 2 2 1

3   Pass
A = 100:-11:1; assert(isequal(hunique(A),A)); [~,H] = hunique(A); assert(isequal(H,ones(1,10)));

U = 100 U = 100 89 U = 100 89 78 U = 100 89 78 67 U = 100 89 78 67 56 U = 100 89 78 67 56 45 U = 100 89 78 67 56 45 34 U = 100 89 78 67 56 45 34 23 U = 100 89 78 67 56 45 34 23 12 U = 100 89 78 67 56 45 34 23 12 1 H = 1 H = 1 1 H = 1 1 1 H = 1 1 1 1 H = 1 1 1 1 1 H = 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 1 1 1 U = 100 U = 100 89 U = 100 89 78 U = 100 89 78 67 U = 100 89 78 67 56 U = 100 89 78 67 56 45 U = 100 89 78 67 56 45 34 U = 100 89 78 67 56 45 34 23 U = 100 89 78 67 56 45 34 23 12 U = 100 89 78 67 56 45 34 23 12 1 H = 1 H = 1 1 H = 1 1 1 H = 1 1 1 1 H = 1 1 1 1 1 H = 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 1 1 H = 1 1 1 1 1 1 1 1 1 1

4   Pass
A = randi([-10 10],1,100); [U,H] = hunique(A); assert(sum(H)==numel(A)); assert(isequal(unique(A),sort(U))); % number of test cases may increace in the future. % any proposals of test cases warmly welcome.

U = -9 U = -9 6 U = -9 6 -6 U = -9 6 -6 -1 U = -9 6 -6 -1 3 U = -9 6 -6 -1 3 -4 U = -9 6 -6 -1 3 -4 5 U = -9 6 -6 -1 3 -4 5 10 U = -9 6 -6 -1 3 -4 5 10 -7 U = -9 6 -6 -1 3 -4 5 10 -7 -10 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 0 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 0 -5 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 0 -5 8 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 0 -5 8 7 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 0 -5 8 7 2 U = -9 6 -6 -1 3 -4 5 10 -7 -10 1 -3 -8 4 9 0 -5 8 7 2 -2 H = 1 H = 1 1 H = 1 1 7 H = 1 1 7 4 H = 1 1 7 4 9 H = 1 1 7 4 9 11 H = 1 1 7 4 9 11 4 H = 1 1 7 4 9 11 4 4 H = 1 1 7 4 9 11 4 4 8 H = 1 1 7 4 9 11 4 4 8 4 H = 1 1 7 4 9 11 4 4 8 4 11 H = 1 1 7 4 9 11 4 4 8 4 11 4 H = 1 1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