Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The string "aabbccddee" is compressed by keeping each character once for every run of length at least two, followed by the count (for example "a2"). Runs of length one are left unchanged. What is the length of the compressed string?

  1. A. 5
  2. B. 15
  3. C. 10
  4. D. 20

Correct answer: C. 10

Every run has length 2, so the output is "a2b2c2d2e2": 5 runs × 2 characters = 10 (the same as the input). Counting only letters gives 5, keeping the run before the count ("aa2") gives 15, and writing a count after every character gives 20.

More Coding Interview Problems questions

Exams that ask this topic