Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for What Is Wrong With This Family? by megaexception
def is_family(tree):
family = {tree[0][0]}
parents = {}
i = 0
while tree and i < len(tree):
f, s = tree[i]
if f in family and s not in family:
family.add(s)
parents[s] = f
tree.pop(i)
i = 0
elif s in family and f not in family:
if parents.get(s):
return False
family.add(f)
tree.pop(i)
i = 0
else:
i += 1
return len(tree)==0
April 26, 2020