Two Characters

  • + 0 comments

    Python using combinations

    def alternate(s):
        comb = list(combinations(set(s), 2))
        len_max = 0
        
        for i in comb:
            txt = s
            txt = "".join(c for c in txt if c in i)        
            if re.search(r"(.)\1", txt):
                continue
            else:
                if len(txt) > len_max:
                    
                    len_max = len(txt)
        
        return len_max