Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: How many substrings of "eceba" contain exactly 2 distinct characters?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Test every substring for exactly two distinct letters. The at-most-two count minus the at-most-one count gives the same result, so the two methods can be used to cross-check.
More Coding Interview Problems questions
- Problem: For the array [3, 1, 4, 1, 5, 9, 2] and window size 3, compute the sum of the minimum of every contiguous window.
- Problem: The Euclidean algorithm is run on (1071, 462). How many division steps (a mod b operations) are performed until the remainder…
- Problem: Count the subarrays of [4, 2, 2, 4, 2] whose maximum equals the minimum (single elements count).
- Problem: Water is poured into the cells of a 1-dimensional array of heights [0,1,0,2,1,0,1,3,2,1,2,1]; each cell holds water up to…
- Problem: Starting at 0 on a line, a walker takes steps +3, −2, +3, −2, … alternating, with 12 steps in total. How many distinct integer…
- Problem: Count the sequences of length 5 over {0, 1, 2} with no two adjacent equal digits and whose first digit is 0.