Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-104

Anti-Diagonal Extraction

Problem

Return the anti-diagonal of a square matrix A: the entries from the top-right corner to the bottom-left.

d[k] = A[k][n - 1 - k] for k = 0, ..., n - 1.

Hint

As the row index increases, the column index decreases.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [2,3]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [3,5,7]
case 3
in: [[[5]]]
expected: [5]
case 4
in: [[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]]
expected: [4,7,10,13]
Starter codePython
def anti_diagonal(A):
    # Your code here
    pass

4 test cases · run your code against them in the editor