Skip to content
Onsite

Reverse N Traversal

EasyP3Coding

Return the elements of an N x N matrix in a reverse-N shape, as one array:

  1. The first column from the top down, stopping before the bottom-left cell.
  2. The anti-diagonal from the bottom-left cell up to the top-right cell.
  3. The last column from the cell below the top-right corner down to the bottom.

Every visited cell appears once.

Example 1

Input
matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output
[1,4,7,5,3,6,9]

Example 2

Input
matrix = [[1,2],[3,4]]
Output
[1,3,2,4]

Example 3

Input
matrix = [[5]]
Output
[5]

Constraints

  • 1 <= N <= 100
  • -10^9 <= matrix[i][j] <= 10^9

Hints

Run checks the 3 visible tests, Submit all 10.