Sort 2D Matrix Diagonally | Coding Interview | Matrix | Sorting
In this article, I have explained the solution for this problem in simple terms.
The approach is very simple; we have to put elements of each diagonal in a list or some other collection (we will discuss it later), then sort them and put them back in the same diagonal.
This article is part of the following preparation plan.
The question is how to access each element of a particular diagonal? And the answer to this problem is that each diagonal in a matrix has a unique I.D. Take any element A[i][j] of a diagonal, then (i-j) is the unique I.D. for that diagonal. In other words, every element A[i][j] of matrix A belongs to the diagonal with the I.D. of i-j.