func diagonalSort(mat [][]int) [][]int { m := len(mat) n := len(mat[0]) lists := make([][]int, m+n) for i := 0; i < m; i++ { for j := 0; j < n; j++ { lists[i-j+n] = append(lists[i-j+n], mat[i][j]) } } for i := m + n - 1; i > 0; i-- { sort.Ints(lists[i]) } for i := 0; i < m; i++ { for j := 0; j < n; j++ { mat[i][j] = lists[i-j+n][0] lists[i-j+n] = lists[i-j+n][1:] } } return mat }