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?
- A. 21
- B. 7
- C. 14
- 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
- Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have…
- Problem: The product of the digits of 2^10 · 3^4 is computed (in decimal). What is that product?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is reduced by repeatedly removing the first two elements and appending their sum to the…
- Problem: For the sequence 2, 3, 5, 7, 11, …, the first 10 prime numbers are listed. What is the sum of the 10th and 7th primes in the list?
- Problem: A bitmask represents a subset of the 4 items {A, B, C, D} by bits 0–3. How many subsets have an even number of items and do NOT…
- Problem: Find the number of ways to select a non-empty subset of {1, 2, 4, 8, 16} whose sum is a multiple of 5.