1class Solution {2public:3void sortmat(int i, int j, vector<vector<int>> &mat, int m, int n, vector<int> &temp) {4if (i >= m || j >= n) {5sort(temp.begin(), temp.end());6return;7}8temp.push_back(mat[i][j]);9sortmat(i + 1, j + 1, mat, m, n, temp);10mat[i][j] = temp.back();11temp.pop_back();12}1314vector<vector<int>> diagonalSort(vector<vector<int>> &mat) {15int m = mat.size();16int n = mat[0].size();17vector<int> temp;18// For column19for (int j = 0; j < n; j++) sortmat(0, j, mat, m, n, temp);20// For Row21for (int i = 1; i < m; i++) sortmat(i, 0, mat, m, n, temp);22return mat;23}24};