Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The string "aabcccccaaa" is run-length encoded (each run becomes its letter followed by its run length, e.g. "a2b1..."). What is the length of the encoded string?

  1. A. 6
  2. B. 7
  3. C. 11
  4. D. 8

Correct answer: D. 8

The runs are aa, b, ccccc, aaa, encoded as a2 b1 c5 a3 = 8 characters. Merging equal letters across runs (a5 b1 c5) gives 6, dropping the count for single letters (a2 b c5 a3) gives 7, and 11 is the original length.

More Coding Interview Problems questions

Exams that ask this topic