Sherlock and the Valid String

  • + 0 comments

    python -

    def isValid(s):

    # Write your code here
    s_dict = {}
    count=0
    for i in s:
        if i in s_dict:
            s_dict[i]+=1
        else:
            s_dict[i]=1
    dict_val_list = list(s_dict.values())
    
    for i in range(1,len(s_dict)):
        if dict_val_list[0] == dict_val_list[i]:
            continue          
        else:
            if count==0:
                count+=1
            else:
                return 'NO'
    return 'YES'