All problems
Commute Time Matrix Property Check
Problem
Verify that a matrix is a valid commute time matrix.
A commute time matrix must be square with zero diagonal, non-negative entries, and perfect symmetry (C[i][j] equals C[j][i]). Return True when all of these hold. matrix is a list of n lists of numbers.
Hint
Commute time is symmetric even on directed graphs because it uses the underlying walk.
Test cases
case 1
in: [[[0,4,8],[4,0,4],[8,4,0]]]
expected: true
case 2
in: [[[0,4],[5,0]]]
expected: false
case 3
in: [[[1,2],[2,0]]]
expected: false
case 4
in: [[[0,-1],[-1,0]]]
expected: false
case 5
in: [[[0]]]
expected: true
Starter codePython
def commute_time_symmetric(matrix):
# Your code here
pass5 test cases · run your code against them in the editor