You are viewing a single comment's thread. Return to all comments →
import re import itertools def alternate(s): maxLen = 0 unique_char = set(s) n = len(unique_char) pattern = re.compile(r'^(\w)(?!\1)(\w)(\1\2)*\1?$') if (n < 2): maxLen = 0 else: for comb in itertools.combinations(unique_char, n-2): x = s for i in comb: x = x.replace(i, "") if (pattern.match(x)): maxLen = max(maxLen, len(x)) return maxLen length = int(input()) s = input() result = alternate(s) print(result)
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 →
for Python3 Platform