Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Count the ordered pairs of words (i, j) with i ≠ j in ["abc", "cba", "bca", "abc", "cab", "xyz"] such that the second word is the reverse of the first.

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

Correct answer: B. 4

Test each ordered pair against the reversal condition. Counting unordered pairs halves the number, and ignoring duplicate words changes the count.

More Coding Interview Problems questions

Exams that ask this topic