This solution passes the test cases, yet it fails in general.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
[b2, ix2] = sortg([], @lt);
assert(isempty(b2) && isempty(ix2));
|
2 | Pass |
a = rand(1, 100);
[b1, ix1] = sort(a);
[b2, ix2] = sortg(a, @lt);
assert(isequal(b1, b2) && isequal(ix1, ix2));
|
3 | Pass |
a = rand(1, 100);
[b1, ix1] = sort(a, 'descend');
[b2, ix2] = sortg(a, @gt);
assert(isequal(b1, b2) && isequal(ix1, ix2));
|
4 | Pass |
a = randn(1, 100) + randn(1, 100)*1i;
[~, ix1] = sort(abs(a));
b1 = a(ix1);
[b2, ix2] = sortg(a, @(a, b) abs(a) < abs(b));
assert(isequal(b1, b2) && isequal(ix1, ix2));
|
5 | Pass |
a = randi(10, 1, 100);
[b1, ix1] = sort(a); % MATLAB's sort() is stable
[b2, ix2] = sortg(a, @lt);
assert(isequal(b1, b2) && isequal(ix1, ix2));
|
2197 Solvers
483 Solvers
Arrange Vector in descending order
4077 Solvers
Who knows the last digit of pi?
557 Solvers
Convert a structure into a string
95 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!