Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
I like recursion! solution in Clear category for How to Find Friends by Denis_Gerashchenko
def check_connection(network, first, second):
splited = [pair.split('-') for pair in network]
checked = []
def rec(robot):
nonlocal splited
nonlocal first
nonlocal second
nonlocal checked
if robot == second:
return True
for pair in splited:
if pair in checked:
continue
if robot in pair:
checked.append(pair)
for unit in pair:
if unit != robot:
return rec(unit)
return False
return rec(first)
May 6, 2019