Anti Diagonals (IB)
Simulation Array
Problem
Given an NxN square matrix, return an array of it's anti-diagonals
For example:
Solution
Key Facts
What really helps solve this problem is understanding how with each movement of the diagonal, the row increases by 1 while the column decreases by 1 (or (1,-1)).
When we're done traversing the top, we need to start from the next row.
All you need to know is how to obtain the first numbers of each diagonal with the for loops and then apply the knowledge of (1, -1) to iterate through the diagonals.
Time Complexity
Last updated
Was this helpful?