Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Double Substring by Rounin
def double_substring(line):
candidates = []
for start in range(0, len(line)-1):
for end in range(start+1, len(line)):
substring = line[start:end]
totallength = len(line)-len(line.replace(substring, ''))
occurrences = totallength / len(substring)
if occurrences > 1:
candidates.append(substring)
return (0 if len(candidates) == 0 else len(sorted(candidates, key=lambda x: -len(x))[0]))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert double_substring('aaaa') == 2, "First"
assert double_substring('abc') == 0, "Second"
assert double_substring('aghtfghkofgh') == 3, "Third"
print('"Run" is good. How is "Check"?')
Aug. 16, 2017