• + 1 comment

    Try with the script below on python and thank me later:)

    def alternate(s):
        valid_substrings = []
        for first, second in combinations(set(s), 2):
            pattern = "[^" + first + second + "]"
            substring = re.sub(pattern, '', s)
            if not re.search(r'([a-z])\1', substring):
                valid_substrings.append(substring)
        return max([len(i) for i in valid_substrings]) if valid_substrings else 0