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?
- A. 6
- B. 4
- C. 5
- 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
- Problem: The minimum ASCII delete sum to make the strings "sea" and "eat" equal is the least total ASCII value of deleted characters. Give…
- Problem: A pattern-matching task uses the string "abxcabcyabd" and the target "abc". How many length-3 windows of the text differ from…
- Problem: Using shell-style wildcards ( matches any run of characters including empty, ? matches exactly one character), how many words in…
- Problem: Choose a subsequence of [2, 3, 5, 7, 8] with no two chosen elements at adjacent positions. How many such non-empty choices sum to…
- Problem: The egg-dropping puzzle with 2 eggs and a 10-floor building: what is the minimum number of drops needed in the worst case to find…
- Problem: How many ways can 10 be made using coins {1, 2, 5} where order does not matter (combinations of coin counts)?