Print Diagonal

Easy
0/40
5 upvotes
Asked in company
ZS

Problem statement

Given a 2D matrix, print all elements of the given matrix in diagonal order.

See the sample input.

Detailed explanation ( Input/output format, Notes, Images )
Input format :
Line 1 : Number of rows R and cols C in the matrix
Line 2 : RXC elements of the matrix separated by space
Output Format :
 Print the diagonals
Constraints :
 1 <= R <= 10^3
 1 <= C <= 10^3
Sample Input :
3 4
8 3 0 7 
0 3 1 8 
3 9 8 7 
Sample Output :
8 
0 3 
3 3 0 
9 1 7 
8 8 
7 
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Print Diagonal
Full screen
Console