Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-063

Determinant of Triangular Matrix

Problem

Compute the determinant of a square triangular matrix (upper or lower triangular) as the product of its diagonal entries.

You may assume the input is triangular.

Hint

All entries above (or below) the diagonal are zero, so only the diagonal matters.

Test cases

case 1
in: [[[2,5,7],[0,3,9],[0,0,4]]]
expected: 24
case 2
in: [[[1,0,0],[2,3,0],[4,5,6]]]
expected: 18
case 3
in: [[[5,0],[0,7]]]
expected: 35
case 4
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: 1
Starter codePython
def det_triangular(A):
    # Your code here
    pass

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