xyz Interview Question for Nones

Country: United States
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
of 1 vote

Elegant Python Solution:

from collections import Counter
def stringCounts(words):
  for word in words:
    c = Counter(word)
    # First sort by counts, then by alphabet
    orderedLetters = sorted(c.items(), key=lambda elem:(-elem[1],elem[0]))
    print('%s: %s' % (word, orderedLetters))

stringCounts(['hello', 'world'])
# Output:
# hello: [('l', 2), ('e', 1), ('h', 1), ('o', 1)]
# world: [('d', 1), ('l', 1), ('o', 1), ('r', 1), ('w', 1)]

- prudent_programmer March 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

C# solution:

public static void PrintHightestCountOrdered(string input)
            //int multiplier = 100;
            if (input == null)
                Console.WriteLine("Invalid input!!!");

            Dictionary<char, int> dictionary = new Dictionary<char, int>();

            foreach(var inputar in input.Split(' '))
                foreach (char chr in inputar)
                    if (dictionary.ContainsKey(chr))
                        dictionary.Add(chr, 1);

                var items = from entry in dictionary
                            orderby entry.Value descending, entry.Key ascending
                            select entry;

                dictionary = new Dictionary<char, int>();

                foreach(var item in items)
                    Console.WriteLine($"{item.Key} - {item.Value} ");


- SRS March 19, 2018 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More