Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The string "xyzxyzxyz" is split into 3 equal blocks of length 3. The blocks are compared: how many pairs of blocks (i < j) are equal as strings?

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

Correct answer: D. 3

All three blocks equal 'xyz', so every one of the three index pairs matches. Counting distinct block contents (one) gives a different quantity than the pair count.

More Coding Interview Problems questions

Exams that ask this topic