You are viewing a single comment's thread. Return to all comments →
My Python solution:
def isValid(w): freq_counter = Counter(w) freq_freq = Counter(freq_counter.values()) if len(freq_freq) == 1: return "YES" elif len(freq_freq) == 2: (k1, v1), (k2, v2) = freq_freq.items() if v1 == 1 and (k1 - 1 == k2 or k1 == 1) or v2 == 1 and (k2 - 1 == k1 or k2 == 1): return "YES" return "NO"
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →
My Python solution: