X

DAYS

:

HOUR

:

MINS

:

SEC

#### Loading...

Copied to Clipboard
Print Diagonally
Easy Accuracy: 67.1% Submissions: 3479 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?

#### My Submissions:

Login to access your submissions.

Print Diagonally