Sherlock and the Valid String

  • + 0 comments

    PYTHON :

    def isValid(s):
        # Write your code here
        a = Counter(s)
        set1 = set(s)
        lst = sorted(list(a[p] for p in set1))
        lst1 = list(i-lst[0] for i in lst)
        
        if sum(lst1)==1 or sum(lst1)==0 or sum(lst1)==(len(lst1)-1)*lst1[-1]:
            return 'YES'
        else:
            return 'NO'