Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
quite simple solution in Clear category for Determine the Order by 1-more
def checkio(words):
predecessors = {}
for c in set(''.join(words)):
predecessors[c] = set(''.join(w[:w.find(c)] for w in words if c in w))
result = ''
while len(result) < len(predecessors):
result += min(k for k, v in predecessors.items() if k not in result and v.issubset(set(result)))
return result
#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 4, 2018
Comments: