Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

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 ≤ 10^{3}

0 ≤ A[i][j] ≤ 10^{6}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

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

YesLoading...

Print Diagonally

...