Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The string "abcdefghij" is read two letters at a time in pairs; each pair (xy) is replaced by the pair reversed (yx). What is the resulting string?

  1. A. abcdefghij
  2. B. jihgfedcba
  3. C. badcfehgji
  4. D. bacdfeghij

Correct answer: C. badcfehgji

Each consecutive pair is swapped in place, so 'ab' becomes 'ba', 'cd' becomes 'dc', and so on. Reversing the whole string instead gives a different result.

More Coding Interview Problems questions

Exams that ask this topic