Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dict [str, set] solution in Clear category for Determine the Order by Bugo-ga
from typing import List, Dict
def create_structure(words: List[str]) -> Dict[str, set]:
structure = {char: set() for char in ''.join(words)}
for word in words:
for idx in range(1, len(word)):
current, preview = word[idx], word[idx - 1]
if current != preview:
structure[current].add(preview)
return structure
def checkio(data: List[str]) -> str:
new_structure = create_structure(data)
target_word = ''
while new_structure:
for char in sorted(new_structure):
if not new_structure[char]:
new_structure.pop(char)
target_word += char
break
else:
raise Exception('Cyclic link found!') # Example: 'abac'
for key, val in new_structure.items():
if char in val:
new_structure[key].remove(char)
return target_word
June 30, 2021
Comments: