Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Long Repeat Inside by Sim0000
def repeat_inside(line):
n = len(line)
maxpos = maxlen = 0
for start in range(n):
for m in range(1, (n - start) // 2 + 1):
p = m
while line[start:start+m] == line[start+p:start+p+m]:
p += m
if p > m and p > maxlen:
maxpos, maxlen = start, p
return line[maxpos:maxpos+maxlen]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert repeat_inside('aabbff') == 'aa', "Second"
assert repeat_inside('aaaaa') == 'aaaaa', "First"
assert repeat_inside('aababcc') == 'abab', "Third"
assert repeat_inside('abc') == '', "Forth"
assert repeat_inside('abcabcabab') == 'abcabc', "Fifth"
print('"Run" is good. How is "Check"?')
Aug. 11, 2017
Comments: