Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6424
@blackshadows 6380
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@mantu_singh 3532
@marius_valentin_dragoi 3523
@sushant_a 3459
Complete Leaderboard
Print Diagonally
Easy Accuracy: 65.54% Submissions: 531 Points: 2

Give a N * N square matrix, return all the elements of its anti-diagonals from top to bottom.

Example 1:

Input: 
N = 2
A = [[1, 2],
     [3, 4]]
Output:
1 2 3 4
Explanation: Topmost anti-diagonal is [[1, ], 
                                       [ , ]]
Next anti-diagonal is [[ , 2], 
​                       [3,  ]]
and the last anti-diagonal is [[ ,  ], 
​                               [ , 4]]
Hence, elements will be returned in the 
order {1, 2, 3, 4}.

Example 2:

Input: 
N = 3 
A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
Output: 
1 2 4 3 5 7 6 8 9

Your Task:
You don't need to read input or print anything. Your task is to complete the function downwardDigonal() which takes an integer N and a 2D matrix A[ ][ ] as input parameters and returns the list of all elements of its anti-diagonals from top to bottom.

Expected Time Complexity: O(N*N)
Expected Auxillary Space: O(N*N)

Constraints:
1 ≤ N, M ≤ 103
0 ≤ A[i][j] ≤ 106

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Print Diagonally

Output Window