We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Sherlock and the Valid String
  5. Discussions

Sherlock and the Valid String

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • guptap8265
    2 months ago+ 0 comments

    def isValid(s):

    c = set(s)
    l = []
    result = "YES"
    for i in c:
        k = s.count(i)
        l.append(k)
    if(max(l) == min(l)):
        return result
    if(max(l)-min(l)== 1):
        if(l.count(min(l))<2 or l.count(max(l))<2):
            return result
        else:
            result = "NO"
            return result
    if(min(l) == 1 and l.count(min(l)==1) and l.count(max(l))==len(l)-1):
        return result
    else:
        result = "NO"  
        return result  
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy