You are viewing a single comment's thread. Return to all comments →
#python 3 def isValid(s): keys = set(s) frequencies = {key:0 for key in keys} for letter in s: frequencies[letter] += 1 counts = Counter(frequencies.values()) maxCount = max(counts.values()) mode = min([key for key, value in counts.items() if value == maxCount]) diff = 0 for letter,num in frequencies.items(): if num != mode: if (abs(num - mode) == 1 or num == 1) and diff == 0: diff += 1 else: return "NO" return "YES"
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →