Data Structures & AlgorithmsModerateTCS NQT · Infosys

In the list ['listen', 'silent', 'enlist', 'google', 'gooegl', 'cat', 'act', 'tac', 'dog'], how many unordered pairs of different positions (i < j) form anagrams of each other?

  1. A. 9
  2. B. 4
  3. C. 7
  4. D. 10

Correct answer: C. 7

Group the words by their sorted letters (or a letter-count signature); each group of size g contributes g·(g−1)/2 pairs. Counting groups instead of pairs answers how many distinct anagram classes exist.

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

Exams that ask this topic