All problems
Adjacency Matrix Check
Problem
Return True if A is a valid adjacency matrix for a simple undirected graph: square with entries in {0, 1}, zero diagonal, and symmetric.
Otherwise return False.
Hint
Simple graphs have no self-loops and no multi-edges, so the diagonal is 0 and entries are 0 or 1.
Test cases
case 1
in: [[[0,1],[1,0]]]
expected: true
case 2
in: [[[0,1],[0,0]]]
expected: false
case 3
in: [[[1,0],[0,1]]]
expected: false
case 4
in: [[[0,2],[2,0]]]
expected: false
Starter codePython
def is_valid_adjacency(A):
# Your code here
pass4 test cases · run your code against them in the editor