Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using brute force solution in Clear category for Long Repeat Inside by H0r4c3
def repeat_inside(line):
"""
first the longest repeating substring
"""
all_substrings = [line[i:j] for i in range(len(line)) for j in range(i+1, len(line) + 1)]
subs_dict = {item:line.count(item) for item in all_substrings if line.count(item) > 1}
if subs_dict == {}:
return ''
for key, value in subs_dict.items():
for i in range(value, 0, -1):
if key*i in line:
subs_dict[key] = i
break
sorted_subs = sorted(subs_dict.items(), key=lambda x : len(x[1]*x[0]), reverse=True)
return sorted_subs[0][0]*sorted_subs[0][1]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert repeat_inside('aaaaa') == 'aaaaa', "First"
assert repeat_inside('aabbff') == 'aa', "Second"
assert repeat_inside('aababcc') == 'abab', "Third"
assert repeat_inside('abc') == '', "Forth"
assert repeat_inside('abcabcabab') == 'abcabc', "Fifth"
print('"Run" is good. How is "Check"?')
Feb. 12, 2022
Comments: