You are viewing a single comment's thread. Return to all comments →
def isValid(s): letters = string.ascii_lowercase word = {key: 0 for key in letters} for char in s: word[char] += 1 final_word = {k: v for k, v in word.items() if v > 0} x = max(final_word.values()) y = min(final_word.values()) if x == y: return "YES" total_x = 0 total_y = 0 for value in final_word.values(): if value == x: total_x += 1 elif value == y: total_y += 1 diff = abs(total_x - total_y) if diff == 0: return "NO" elif total_x == 1 or total_y == 1: if abs(x-y) == 1 or y * total_y == 1 or x * total_x == 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 →