Posts

Showing posts from July, 2021

Company Logo | HackerRank Solutions

  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,  would have it's logo with the letters  . Input Format A single line of input containing the string  . Constraints  has at least   distinct characters 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...

Collections.deque() HackerRank Solutions

  collections.deque() A  deque  is a double-ended queue. It can be used to add or remove elements from both ends. Deques support thread safe, memory efficient appends and pops from either side of the deque with approximately the same   performance in either direction. Click on the link to learn more about  deque() methods . Click on the link to learn more about various approaches to working with deques:  Deque Recipes . Example Code >>> from collections import deque >>> d = deque() >>> d.append(1) >>> print d deque([1]) >>> d.appendleft(2) >>> print d deque([2, 1]) >>> d.clear() >>> print d deque([]) >>> d.extend('1') >>> print d deque(['1']) >>> d.extendleft('234') >>> print d deque(['4', '3', '2', '1']) >>> d.count('1') 1 >>> d.pop() '1' >>> print d deque(['4', '3'...