Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for New Cities by pokosasa
def subnetworks(net, crushes):
res=[]
for link in net:
link=set(link)-set(crushes)
if link==set():
continue
for sub_net in res.copy():
if link & sub_net:
link |= sub_net
res.remove(sub_net)
res.append(link)
return len(res)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert subnetworks([
['A', 'B'],
['B', 'C'],
['C', 'D']
], ['B']) == 2, "First"
assert subnetworks([
['A', 'B'],
['A', 'C'],
['A', 'D'],
['D', 'F']
], ['A']) == 3, "Second"
assert subnetworks([
['A', 'B'],
['B', 'C'],
['C', 'D']
], ['C', 'D']) == 1, "Third"
print('Done! Check button is waiting for you!')
Aug. 19, 2019