Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The string "aabbbcccc" is encoded by writing each letter followed by its count, e.g. "a2b3c4". What is the length of the encoded string?

  1. A. 9
  2. B. 6
  3. C. 3
  4. D. 18

Correct answer: B. 6

Each run contributes its letter and a one-digit count: a2 b3 c4 = 6 characters. 9 is the original length, 3 counts only the letters, and writing a letter-count pair for every character gives 18.

More Coding Interview Problems questions

Exams that ask this topic