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.
#!/bin/python3importmathimportosimportrandomimportreimportsysfromcollectionsimportCounterif__name__=='__main__':s=input()#Gettheinputstring# Count the frequency of each charactercounter=Counter(s)# Sort by frequency in descending order and by character in ascending ordermost_common=sorted(counter.items(),key=lambdax:(-x[1],x[0]))# Print the top 3 most common charactersforiinrange(3):char,count=most_common[i]print(char,count)
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 →