Cody

# Problem 44888. Given a matrix A (size m x n) create a matrix B which consists of matrix A sorted in descending order by columns and then by rows.

Solution 2655749

Submitted on 5 Jul 2020 at 18:30 by Ramesh Kumar V
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 = [2 6 -3 7 12 0 -12 5 1]; y_correct = [12 7 1 6 2 0 5 -3 -12]; assert(isequal(doubleSort(x),y_correct))

m = 3 n = 3 y = 0 0 0 0 0 0 0 0 0 z = 2 7 -12 z1 = 7 2 -12 y = 7 0 0 2 0 0 -12 0 0 z = 6 12 5 z1 = 12 6 5 y = 7 12 0 2 6 0 -12 5 0 z = -3 0 1 z1 = 1 0 -3 y = 7 12 1 2 6 0 -12 5 -3 z = 7 12 1 z1 = 12 7 1 y1 = 12 7 1 z = 2 6 0 z1 = 6 2 0 y1 = 12 7 1 6 2 0 z = -12 5 -3 z1 = 5 -3 -12 y1 = 12 7 1 6 2 0 5 -3 -12

2   Pass
x = randi(10,5,8); assert(isequal(size(doubleSort(x)),size(x)))

m = 5 n = 8 y = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 z = 8 8 4 2 8 z1 = 8 8 8 4 2 y = 8 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 z = 7 10 3 9 8 z1 = 10 9 8 7 3 y = 8 10 0 0 0 0 0 0 8 9 0 0 0 0 0 0 8 8 0 0 0 0 0 0 4 7 0 0 0 0 0 0 2 3 0 0 0 0 0 0 z = 4 5 9 7 9 z1 = 9 9 7 5 4 y = 8 10 9 0 0 0 0 0 8 9 9 0 0 0 0 0 8 8 7 0 0 0 0 0 4 7 5 0 0 0 0 0 2 3 4 0 0 0 0 0 z = 8 7 9 4 4 z1 = 9 8 7 4 4 y = 8 10 9 9 0 0 0 0 8 9 9 8 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18 17 16 9 8 7 15 14 13 6 5 4 12 11 10 3 2 1]; assert(isequal(doubleSort(x),y_correct))

m = 6 n = 6 y = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 z = 35 3 31 8 30 4 z1 = 35 31 30 8 4 3 y = 35 0 0 0 0 0 31 0 0 0 0 0 30 0 0 0 0 0 8 0 0 0 0 0 4 0 0 0 0 0 3 0 0 0 0 0 z = 1 32 9 28 5 36 z1 = 36 32 28 9 5 1 y = 35 36 0 0 0 0 31 32 0 0 0 0 30 28 0 0 0 0 8 9 0 0 0 0 4 5 0 0 0 0 3 1 0 0 0 0 z = 6 7 2 33 34 29 z1 = 34 33 29 7 6 2 y = 35 36 34 0 0 0 31 32 33 0 0 0 30 28 29 0 0 0 8 9 7 0 0 0 4 5 6 0 0 0 3 1 2 0 0 0 z = 26 21 22 17 12 13 z1 = 26 22 21 17 13 12 y = 35 36 34 26 0 0 31 32 33 22 0 0 30 28 29 21 0 0 8 9 7 17 0 0 4 5 6 13 0 0 3 1 2 12 0 0 z = 19 23 27 10 14 18 z1 = 27 23 19 18 14 10 y = 35 36 34 26 27 0 31 32 33 22 23 0 30 28 29 21 19 0 8 9 7 17 18 0 4 5 6 13 14 0 3 1 2 12 10 0 z = 24 25 20 15 16 11 z1 = 25 24 20 16 15 11 y = 35 36 34 26 27 25 31 32 33 22 23 24 30 28 29 21 19 20 8 9 7 17 18 16 4 5 6 13 14 15 3 1 2 12 10 11 z = 35 36 34 26 27 25 z1 = 36 35 34 27 26 25 y1 = 36 35 34 27 26 25 z = 31 32 33 22 23 24 z1 = 33 32 31 24 23 22 y1 = 36 35 34 27 26 25 33 32 31 24 23 22 z = 30 28 29 21 19 20 z1 = 30 29 28 21 20 19 y1 = 36 35 34 27 26 25 33 32 31 24 23 22 30 29 28 21 20 19 z = 8 9 7 17 18 16 z1 = 18 17 16 9 8 7 y1 = 36 35 34 27 26 25 33 32 31 24 23 22 30 29 28 21 20 19 18 17 16 9 8 7 z = 4 5 6 13 14 15 z1 = 15 14 13 6 5 4 y1 = 36 35 34 27 26 25 33 32 31 24 23 22 30 29 28 21 20 19 18 17 16 9 8 7 15 14 13 6 5 4 z = 3 1 2 12 10 11 z1 = 12 11 10 3 2 1 y1 = 36 35 34 27 26 25 33 32 31 24 23 22 30 29 28 21 20 19 18 17 16 9 8 7 15 14 13 6 5 4 12 11 10 3 2 1