Data Structures & AlgorithmsHardICPC regional · Product Company SDE
Problem: What is the length of the longest substring of "aabbcbbcc" in which every character occurs at least twice?
- A. 4
- B. 2
- C. 9
- D. 7
Correct answer: C. 9
The whole string has a ×2, b ×4, c ×3, so all 9 characters qualify. Requiring exactly two of each gives 4 ("aabb"), a single run gives 2, and skipping the leading "aa" gives 7.
More Coding Interview Problems questions
- Problem: In how many ways can 15 be written as a sum of distinct odd positive integers (order does not matter)?
- Problem: How many non-decreasing strings of length 4 over the digits {0, 1, 2} exist (each digit is at least the one before it)?
- Problem: Can the array [1, 5, 11, 5] be split into two subsets with equal sums? Answer 1 for yes and 0 for no.
- Problem: A wooden stick of length 7 must be cut at the marked positions 1, 3, 4 and 5 (measured from one end). Each cut costs the current…
- Problem: The elimination game: numbers 1 to 9 are written in a row. Repeatedly remove alternate numbers, starting from the left, then from…
- Problem: The 3-bit Gray code sequence is 000, 001, 011, 010, 110, 111, 101, 100 for indices 0 to 7. What is the decimal value of the…