HackerRank Python - Company Logo
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.
- import math
- import os
- import random
- import re
- import sys
- import collections
- s = sorted(input().strip())
- s_counter = collections.Counter(s).most_common()
- s_counter = sorted(s_counter, key=lambda x: (x * -1, x))
- for i in range(0, 3):
- print(s_counter[i], s_counter[i])