Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: What is the value printed by this snippet? from collections import Counter print(Counter("abracadabra").most_common(2))

  1. A. [('a', 5), ('r', 2)]
  2. B. [('a', 5), ('c', 1)]
  3. C. [('a', 5), ('b', 2)]
  4. D. [('b', 2), ('a', 5)]

Correct answer: C. [('a', 5), ('b', 2)]

most_common returns counts in descending order, and equal counts keep their first-seen order. Counting letters manually and reading them in alphabetical order gives a different pair.

More Coding Interview Problems questions

Exams that ask this topic