You are viewing a single comment's thread. Return to all comments →
One more solution without regexp:
import itertools def is_t(s): if len(s) < 2: return False return all(c == s[0] for c in s[2::2]) and all(c == s[1] for c in s[3::2]) s_len = int(input().strip()) s = input().strip() chars_in_s = { list(s) } max_t_len = 0 for c1, c2 in itertools.combinations(chars_in_s, 2): filtered_str = ''.join(c for c in s if c in {c1, c2}) if is_t(filtered_str): max_t_len = max(max_t_len, len(filtered_str)) print(max_t_len)
May be not the fastest, but passes tests and easy to understand.
Two Characters
You are viewing a single comment's thread. Return to all comments →
One more solution without regexp:
May be not the fastest, but passes tests and easy to understand.