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.
importmathimportosimportrandomimportreimportsysdefocc_desc(string):dist={}foriinstring:dist[i]=dist.get(i,0)+1# Sort by frequency (descending), then by character (ascending)sorted_items=sorted(dist.items(),key=lambdaitem:(-item[1],item[0]))# Print top 3forkey,valueinsorted_items[:3]:print(f"{key} {value}")if__name__=='__main__':s=input()occ_desc(s)
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 →