We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
sum = 0
pos = {ch:[i.start() for i in re.finditer(ch, s)] for ch in set(s)}
for j in (x for x in combinations(pos, 2) if abs(len(pos[x[0]])-len(pos[x[1]]))<=1):
s_pos = (j[0], j[1]) if pos[j[0][0]] < pos[j[1][0]] else (j[1], j[0])
if len(pos[s_pos[0]]) < len(pos[s_pos[1]]):
continue
comb = [x for x in (chain.from_iterable((n for n in zip_longest(pos[s_pos[0]], pos[s_pos[1]], fillvalue='_')))) if x != '_']
if comb == sorted(comb):
sum = max(sum, len(comb))
return sum
Cookie support is required to access HackerRank
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 →
def alternate(s):