You are viewing a single comment's thread. Return to all comments →
First I totally misunderstood the problem, but now I got it. Here's my Python2 solution without regex (with the help of itertools):
def twoCharaters(s): combinations_of_two_letters = [i for i in combinations(set(s), 2)] stack = [] for tupl in combinations_of_two_letters: copy_s = copy.deepcopy(s) for letter in copy_s: if letter not in tupl: copy_s = copy_s.replace(letter, '') stack.append(copy_s) copy_stack = copy.deepcopy(list(set(stack))) for item in copy_stack: for index, j in enumerate(item): if item[index:(index+2)] == j*2: stack.remove(item) break return len(max(stack, key=len)) if stack else 0
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
First I totally misunderstood the problem, but now I got it. Here's my Python2 solution without regex (with the help of itertools):