Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 561 Bytes

File metadata and controls

24 lines (20 loc) · 561 Bytes

Diagonal Traversal

Easy


  1. You are given a number n, representing the number of rows and columns of a square matrix.
  2. You are given n * n numbers, representing elements of 2d array a.
  3. You are required to diagonally traverse the upper half of the matrix and print the contents.

Example 1:

Input:  n=4, 
arr = { 1   2   3   4
        5   6   7   8
        9  10  11  12
       13  14  15  16 }
Output:  1 6 11 16 2 7 12 3 8 4

Constraints:

1 <= n <= 10^2
-10^9 <= e11, e12, .. n * m elements <= 10^9