Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Find the length of the longest substring of "aaabbbbcccd" that contains at most two distinct letters.
- A. 4
- B. 7
- C. 10
- D. 11
Correct answer: B. 7
"aaabbbb" has two letters and length 7; the b- and c-runs give only 4 + 3. A single run gives 4, three letters gives "aaabbbbccc" (10), and 11 is the whole string.
More Coding Interview Problems questions
- Problem: How many numbers from 1 to 1000 have a digit sum divisible by 9?
- Problem: How many ways are there to write 20 as an ordered sum of parts from {2, 3, 5}?
- Problem: The sequence a0 = 0 and a(n) = a(n−1) + (n mod 3) for n ≥ 1 is defined. What is a(30)?
- Problem: A square matrix 4×4 has entry (i, j) equal to (i + 2j) mod 5. What is the sum of the entries on the main diagonal?
- Problem: The sum of the squares of the first 15 natural numbers, reduced modulo 7, is what value?
- Problem: Consider the array [3, 7, 4, 9, 2, 8, 5]. Two selection rounds are performed: first pick the largest value and remove it, then…