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?
- A. 5
- B. 15
- C. 10
- 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
- Problem: Calculate the number of ordered pairs (x, y) of integers with 1 ≤ x, y ≤ 20 for which x² + y² is divisible by 5.
- Problem: A lattice path goes from (0,0) to (3,3) using steps right (1,0) and up (0,1), and it must never go above the diagonal (that is…
- Problem: The array [1, 2, 4, 8, 16, 32] stores powers of two. For how many pairs (i < j) is a[i] + a[j] a power of two?
- Problem: A queue of 5 customers arrives with service times 4, 2, 6, 1, 3. A single server processes them in order (first come first…
- Problem: Starting with the list [3, 8, 2, 5], repeatedly take the last two elements, replace them by their difference (larger minus…
- Problem: How many 3-digit numbers (100–999) have digits that form a strictly increasing sequence when read left to right?