Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Determine the Order by mortonfox
def checkio(data):
deps = {}
for word in data:
if word[0] not in deps:
deps[word[0]] = set()
for frm, to in zip(word[:-1], word[1:]):
if frm == to:
continue
if to not in deps:
deps[to] = set()
deps[to].add(frm)
alph = ''
visited = set()
while True:
poss = sorted([c for c in deps.keys() if c not in visited and deps[c] <= visited])
if not poss:
break
alph += poss[0]
visited.add(poss[0])
return alph
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(["acb", "bd", "zwa"]) == "zwacbd", \
"Just concatenate it"
assert checkio(["klm", "kadl", "lsm"]) == "kadlsm", \
"Paste in"
assert checkio(["a", "b", "c"]) == "abc", \
"Cant determine the order - use english alphabet"
assert checkio(["aazzss"]) == "azs", \
"Each symbol only once"
assert checkio(["dfg", "frt", "tyg"]) == "dfrtyg", \
"Concatenate and paste in"
May 25, 2017
Comments: