Cody

Problem 1985. How unique?

Solution 2571918

Submitted on 17 Jun 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   Fail
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));

Error using unique (line 121) Unrecognized flag 'ststic'. Valid flags are 'rows', 'first', 'last', 'stable', 'sorted', 'legacy'. Error in hunique (line 2) U=unique(A,'ststic'); Error in Test1 (line 2) [U, H] = hunique(A);

2   Fail
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));

Error using unique (line 121) Unrecognized flag 'ststic'. Valid flags are 'rows', 'first', 'last', 'stable', 'sorted', 'legacy'. Error in hunique (line 2) U=unique(A,'ststic'); Error in Test2 (line 2) [U, H] = hunique(A);

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

Error using unique (line 121) Unrecognized flag 'ststic'. Valid flags are 'rows', 'first', 'last', 'stable', 'sorted', 'legacy'. Error in hunique (line 2) U=unique(A,'ststic'); Error in Test3 (line 2) assert(isequal(hunique(A),A));

4   Fail
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.

Error using unique (line 121) Unrecognized flag 'ststic'. Valid flags are 'rows', 'first', 'last', 'stable', 'sorted', 'legacy'. Error in hunique (line 2) U=unique(A,'ststic'); Error in Test4 (line 2) [U,H] = hunique(A);