Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: How many adjacent positions i (0 ≤ i < n−1) of "abbaabab" form the pair "ab" or the pair "ba"?

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

Correct answer: C. 5

Check each adjacent pair against the two targets. Counting only 'ab' misses the reversed pairs 'ba' that also qualify.

More Coding Interview Problems questions

Exams that ask this topic