All problems
Matrix Trace
Problem
Compute the trace of a square matrix A (sum of diagonal elements).
Test cases
case 1
in: [[[1,2],[3,4]]]
expected: 5
case 2
in: [[[5,0,0],[0,6,0],[0,0,7]]]
expected: 18
case 3
in: [[[42]]]
expected: 42
Starter codePython
def trace(A):
# Your code here
pass3 test cases · run your code against them in the editor