You are viewing a single comment's thread. Return to all comments →
Python3:
def alternate(s): mem = Counter(s) cb = filter(lambda p: abs(mem[p[0]] - mem[p[1]]) <= 1, combinations(mem.keys(), 2)) cb = sorted(cb, key= lambda p: mem[p[0]] + mem[p[1]], reverse= True) for c1, c2 in cb: ss = [c for c in s if c in (c1, c2)] if all(ss[i] != ss[i+1] for i in range(len(ss) - 1)): return len(ss) return 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 →
Python3: