Data Structures & AlgorithmsModerateWipro · Accenture pattern

What is printed? (anagram check two ways)

What is printed? (anagram check two ways)
from collections import Counter
x, y = "listen", "enlists"
print(sorted(x) == sorted(y), Counter(x) == Counter(y), set(x) == set(y))
  1. A. True True True
  2. B. False True True
  3. C. False False False
  4. D. False False True

Correct answer: D. False False True

"enlists" has an extra 's', so sorted letters and counts differ – not anagrams. A set comparison ignores multiplicity and wrongly says True. Sorting is O(n log n); counting is O(n).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic