Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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 s, which is the company name in lowercase letters, your task is to find the top three most common characters in the string.
For example, according to the conditions described above,
GOOGLE would have it’s logo with the letters G, O, E.
A single line of input containing the string S.
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.
aabbbccde
b 3
a 2
c 2
aabbbccde
Here, b occurs 3 times. It is printed first.Both a and c occur 2 times. So, a is printed in the second line and c in the third line because a comes before c in the alphabet.
Note: The string S has at least 3 distinct characters.
from sys import stdin
S = stdin.readline()
d = {}
for c in S:
if c in d:
d[c] += 1
else:
d[c] = 1
data = [[d[c],c] for c in d.keys()]
data.sort(key = lambda e: [-e[0],e[1]])
for x in range(3):
print data[x][1], data[x][0]
#!/bin/python3
import math
import os
import random
import re
import sys
from collections import Counter
class OrderedCounter(Counter):
pass
if __name__ == '__main__':
[print(*c) for c in OrderedCounter(sorted(input())).most_common(3)]
# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import Counter
string = sorted(Counter(raw_input()).items(), key= lambda x: (-x[1],x[0]))[:3]
print "\n".join(x[0]+" "+str(x[1]) for x in string)
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
pass
[print(*c) for c in OrderedCounter(sorted(input())).most_common(3)]
In our experience, we suggest you solve this T Company Logo Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
Company Logo is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution
I hope this Company Logo Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Hacker Rank Problem & Solutions >>
itertools.product() Hacker Rank Solution
String Validators Hacker Rank Solution
Text Alignment Hacker Rank solution