Pramp Coding Interview - Data structure and Algorithms by Microsoft Engineer

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Thanks for this!

I came up with the following- any edits or suggestions?

def connected(a, b):
if len(a) != len(b):
return False
return len([1 for c, d in list(zip(a, b)) if c != d]) == 1


def search(source, target, words):

q = [(source, 0)]
visited = set()

while q:
c, d = q.pop()

if c in visited:
continue

visited.add(c)

if c == target:
return d

children = [x for x in words if connected(c, x)]

q.extend([(x, d + 1) for x in children])

return -1

rfdickerson
Автор

WOW, thank you!
Are Pramp's questions the same level as big companies?

AbanoubAsaad-YT
join shbcf.ru