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.
# Count character frequencies
for char in s:
if char not in words:
words[char] = 1
else:
words[char] += 1
fixed = sorted(words.items(), key=lambda item: (-item[1], item[0]))
for i, (char, freq) in enumerate(fixed):
if i >= 3: # Stop after printing the top 3
break
print(f"{char} {freq}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Company Logo
You are viewing a single comment's thread. Return to all comments →
fixed: words = {}
if name == 'main': s = input()