top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Anti Diagonals Interviewbit Solution

Sep 1, 2020
1 min read

Updated: Sep 8, 2020


Problem Description:

Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details.


Example:

Input: 	

1 2 3
4 5 6
7 8 9

Return the following :

[ 
  [1],
  [2, 4],
  [3, 5, 7],
  [6, 8],
  [9]
]
Input : 
1 2
3 4

Return the following  : 

[
  [1],
  [2, 3],
  [4]
]

Solution:


1 Comment


The grid layout on https://bitcoincasinoplay.net reminded me of this matrix, so the anti-diagonal solution made sense once I saw each diagonal as a set of cells with the same index sum. Starting from the top row and then the rightmost column gave me a clean way to loop through them without drawing the matrix.

Like
bottom of page