Most Common Char in Company Name
A newly opened multinational brand has decided to base their company logo on the three most common characters in the company name. They are now trying out various combinations of company names and logos based on this condition. Given a string , which is the company name in lowercase letters, your task is to find the top three most common characters in the string.
- Print the three most common characters along with their occurrence count.
- Sort in descending order of occurrence count.
- If the occurrence count is the same, sort the characters in alphabetical order.
For example, according to the conditions described above,
google would have it's logo with the letters g,o,e
.
Input Format
A single line of input containing the string S
Constraints
None
Output Format
Print the three most common characters along with their occurrence count each on a separate line. Sort output in descending order of occurrence count. If the occurrence count is the same, sort the characters in alphabetical order.
Sample Input 0
apple
Sample Output 0
p 2
a 1
e 1
Sample Input 1
accenture
Sample Output 1
c 2
e 2
a 1
Solution:
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
pass
[print(*c) for c in OrderedCounter(sorted(input())).most_common(3)]
Most Common Char in Company Name ,Hackerrank solution By CodexRitik
Reviewed by CodexRitik
on
February 01, 2020
Rating:
Bahut khub bro...
ReplyDeleteBahut sort hai coad.
ReplyDeleteThanks for feedback.
ReplyDeletenice bLog! its interesting. thank you for sharing.... name for new company
ReplyDelete