Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE
Problem: For the string "aaabbbbcc" with at most one replacement of any character by any other letter, what is the length of the longest substring that can be made to consist of one repeated letter?
- A. 6
- B. 5
- C. 4
- D. 7
Correct answer: B. 5
Within a window, one replacement suffices when the window length minus its most common letter count is at most one. Checking only runs of identical letters misses windows that span a single different letter.
More Coding Interview Problems questions
- Problem: The array [1, 4, 3, 2] (with even length) is split into two-element pairs in any way, and the minimum of each pair is added up…
- Problem: A matrix stores the number of paths in a 3×3 grid where each cell can be entered from the left or from above, and blocked cells…
- Problem: The string "racecar" has length 7. How many of its substrings are palindromes with length at least 3? Count index ranges.
- Problem: Count the pairs (i, j) with i < j in the array [1, 5, 2, 8, 3, 5] whose absolute difference is at most 2.
- Problem: A dice-throwing game: starting at 0, each throw adds a value from 1 to 6, and the player stops as soon as the total is at least…
- Problem: Dijkstra is run on a directed graph with arcs 0→1 (5), 0→2 (2), 2→1 (1), 1→3 (2), 2→3 (7), 3→4 (1), 2→4 (9). Each vertex is…