• + 0 comments

    Python Solution

    def happyLadybugs(b):
            # Write your code here
    
            for colour in set(b):
                    if colour != "_" and b.count(colour) == 1:
                            return "NO"
    
            if b.count("_") > 0:
                    return "YES"
    
            for i in range(len(b)):
                    if i == 0 and b[0] != b[1]:
                            return "NO"
                    if i == len(b) - 1 and b[-1] != b[-2]:
                            return "NO"
                    if b[i] != b[i-1] and b[i] != b[i+1]:
                            return "NO"
    
            return "YES"