Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
max, slice solution in Clear category for Long Repeat Inside by imloafer
def repeat_inside(line: str) -> str:
"""
first the longest repeating substring
"""
# your code here
if (line == '') or (line[0] * len(line) == line):
return line
return max(longest, key=len) if (longest := [text for i in range(len(line)//2 + 1)
for j in range(i+1, len(line)//2 + 2)
if (text := line[i:j] * 2) in line]) else ''
print("Example:")
print(repeat_inside("aabbff"))
assert repeat_inside("aaaaa") == "aaaaa"
assert repeat_inside("abcabcabab") == "abcabc"
assert repeat_inside('') == ''
assert repeat_inside("aabbff") == "aa"
assert repeat_inside("aababcc") == "abab"
assert repeat_inside("abc") == ""
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 6, 2022
Comments: