Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
topological solution in Clear category for Determine the Order by gyahun_dash
def topological_sorting(vertices, edges): #with recursion
starts = {v for v in vertices if not any(e.endswith(v) for e in edges)}
if not starts: raise StopIteration
first = min(starts)
yield first
passed = {edge for edge in edges if edge.startswith(first)}
candidates = starts.difference(first) | {edge[1] for edge in passed}
yield from topological_sorting(candidates, edges - passed)
def checkio(strings): #use strings as edges
edges = {p + q for s in strings for p, q in zip(s, s[1:]) if p != q}
return ''.join(topological_sorting({s[0] for s in strings}, edges))
Sept. 8, 2014
Comments: