Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regular Expression solution in Clear category for Double Substring by rossras
import re
def double_substring(line):
# Regex: at least one character (group 1), 0 or more characters, then group
# 1 again. (?=...) looks ahead without consuming, allowing matches to
# overlap. Findall returns all possible values for group 1; find max
# length.
return max((len(m) for m in re.findall(r'(?=(.+).*\1)', line)), default=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. 10, 2018
Comments: