Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
4 problems 1 solution solution in Clear category for Double Substring by StefanPochmann
# The common boring part
def longest_substring(string, predicate):
n = len(string)
for length in range(n, -1, -1):
for start in range(n - length + 1):
substring = string[start:start+length]
if predicate(substring):
return substring
def repeat_inside(line):
return longest_substring(line, lambda s: s in (s + s)[1:-1])
def non_repeat(line):
return longest_substring(line, lambda s: len(s) == len(set(s)))
def long_repeat(line):
return len(longest_substring(line, lambda s: len(set(s)) < 2))
def double_substring(line):
return len(longest_substring(line, lambda s: line.count(s) > 1 or not s))
Aug. 14, 2017
Comments: