A matrix diagonal is the line of cells that starts at a cell in the top row or the left column and moves down and to the right until it leaves the matrix. Given an m x n matrix mat of integers, sort every matrix diagonal in ascending order and return the resulting matrix.
A matrix diagonal is the line of cells that starts at a cell in the top row or the left column and moves down and to the right until it leaves the matrix. Given an m x n matrix mat of integers, sort every matrix diagonal in ascending order and return the resulting matrix.
Example 1:
Input: {"mat":[[3,3,1,1],[2,2,1,2],[1,1,1,2]]}
Output: [[1,1,1,1],[1,2,2,2],[1,2,3,3]]
Constraints:
m=mat.length
n=mat[i].length
1≤m,n≤100
1≤mat[i][j]≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"mat":[[3,3,1,1],[2,2,1,2],[1,1,1,2]]}
A 3 x 4 matrix has 6 diagonals running down and to the right. Each one is sorted on its own, smallest value at the top-left.