You are viewing a single comment's thread. Return to all comments →
Not an easy task at first glance! In Python I think "Counter" is useful to find the longest solution without checking all pairs of characters:
from collections import Counter from itertools import combinations input() # skip s = input() C = Counter(s) for pair in combinations(sorted(C, key=C.get, reverse=True), 2): T = [c for c in s if c in pair] if all(c1 != c2 for c1, c2 in zip(T, T[1:])): print(len(T)) break else: print(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 →
Not an easy task at first glance! In Python I think "Counter" is useful to find the longest solution without checking all pairs of characters: