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.
fromcollectionsimportCounterif__name__=='__main__':s=input().strip()# Count the occurrences of each charactercount=Counter(s)# Sort by frequency (descending) and then alphabetically for tiessorted_count=sorted(count.items(),key=lambdax:(-x[1],x[0]))# Print the top three charactersforchar,freqinsorted_count[:3]:print(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 →
All TestCases Passed