Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The string "aaaa" can be written as a concatenation of the pieces "a" and "aa" in several ways (order matters). How many such ways are there?

  1. A. 6
  2. B. 4
  3. C. 5
  4. D. 7

Correct answer: C. 5

The last piece is either 'a' or 'aa', giving a Fibonacci recurrence. Counting only the splits into singletons gives 1 and misses all others.

More Coding Interview Problems questions

Exams that ask this topic