Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this occurrence). What is the sum of the resulting numbers?

  1. A. 21
  2. B. 7
  3. C. 14
  4. D. 4

Correct answer: C. 14

Running counts are a1 b1 a2 c1 a3 b2 a4: 1 + 1 + 2 + 1 + 3 + 2 + 4 = 14. Using total frequencies gives 21, 7 is the length, and 4 is the final count of 'a'.

More Coding Interview Problems questions

Exams that ask this topic