we will use a 2D vector to store the diagonals of our array the 2D vector will have ( n + m - 1 ) rows that is equal to the number of diagnols
List < List < int > > ans = new List < List < int > > ( n + m - 1 ) ; for ( int i = 0 ; i < n + m - 1 ; i ++ ) { ans . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { ( ans [ i + j ] ) . Add ( arr [ i , j ] ) ; } } for ( int i = 0 ; i < ans . Count ; i ++ ) { for ( int j = ans [ i ] . Count - 1 ; j >= 0 ; j -- ) { Console . Write ( ans [ i ] [ j ] + " ▁ " ) ; } Console . WriteLine ( ) ; } }