Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
(-(-_(-_-)_-)-) solution in Clear category for How to Find Friends by vmiimu
def check_connection(network, first, second):
nodes = {n:set() for net in network for n in net.split('-')}
for n in network:
k,v = n.split('-')
nodes[k].add(v)
nodes[v].add(k)
def find_path(nodes, start, end, path=[]):
path = path + [start]
if start == end:
return path
if not start in nodes:
return None
for node in nodes[start]:
if node not in path:
newpath = find_path(nodes, node, end, path)
if newpath: return newpath
return None
return False if not find_path(nodes, first, second) else True
Dec. 14, 2018
Comments: