Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

For the string "abcdeca", take all length-2 substrings and hash each with h(xy) = (ord(x) + 2*ord(y)) mod 5. How many index pairs i < j of length-2 substrings collide (equal hash)?

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

Correct answer: A. 2

Compute the hash of each of the six length-2 substrings and count equal pairs. Equal substrings always collide, but unequal ones can collide too, and the question counts both kinds.

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

Exams that ask this topic