Sherlock and the Valid String

  • + 0 comments

    def isValid(s):

    l=len(s)
    
    sset=set(s)
    
    if len(set(Counter(s).values()))<=1:
           return "YES"
    
    f=False
    
    for ii in sset:
        if len(set(Counter(s.replace(ii,"",1)).values()))<=1:
            f=True
            break
    
    if f:
        return "YES"
    else:
        return "NO"