304 North Cardinal St.
Dorchester Center, MA 02124

Company Logo Hacker Rank Solution – Queslers

Problem: Company Logo Hacker Rank Solution

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.

• 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 :

• 3 < len(S) <= 10^4

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 :

``````aabbbccde
``````

Sample Output :

``````b 3
a 2
c 2
``````

Explanation :

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.

Company Logo Hacker Rank Solution in python 2

``````from sys import stdin

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]``````

Company Logo Hacker Rank Solution in python 3

``````#!/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)]``````

Company Logo Hacker Rank Solution in pypy

``````# 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)
``````

Company Logo Hacker Rank Solution in pypy 3

``````from collections import Counter, OrderedDict

class OrderedCounter(Counter, OrderedDict):
pass
[print(*c) for c in OrderedCounter(sorted(input())).most_common(3)]
``````
Company Logo Hacker Rank Solution Review:

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

Conclusion:

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

String validators Hacker Rank Solution