Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Under the hash h(s) = sum of the character codes of s, how many of the 3-letter strings "abc", "cab", "bac", "xyz", "zyx" share their hash with at least one other string in the list?

  1. A. 2
  2. B. 4
  3. C. 3
  4. D. 5

Correct answer: D. 5

Anagrams always share a sum-of-codes hash, so the three permutations of abc collide with one another, and xyz with zyx also collides. Counting those with a partner gives the answer.

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

Exams that ask this topic