All problems
Markov Blanket Size
Problem
The Markov blanket of a node in a Bayesian network consists of its parents, its children, and the other parents of its children. Given directed edges as [parent, child] pairs and a node index, return the number of distinct nodes in its Markov blanket. Return 0 for malformed edges.
Hint
Union the parents, the children, and everyone who shares a child with the node.
Test cases
case 1
in: [[[0,1],[2,1],[1,3]],1]
expected: 3
case 2
in: [[[0,1],[2,1],[1,3]],0]
expected: 2
case 3
in: [[[0,1],[0,2]],0]
expected: 2
case 4
in: [[[1,2],[3,2],[1,4],[3,4]],1]
expected: 3
case 5
in: [[],0]
expected: 0
Starter codePython
def markov_blanket_size(edges, node):
# Your code here
pass5 test cases · run your code against them in the editor