x

You can reuse the str_reduce for this.
        two_sol = str_reduce(a)
        answer = len(two_sol) if two_sol else 2