Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional
Problem: For the string "AABABBA" and k = 1, you may replace at most one character with any other letter. What is the length of the longest substring that can become a block of identical letters?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
A substring can be made uniform with k changes when its length minus its most frequent letter count is at most k. Replacing the first mismatch only, instead of the best letter, gives a shorter window.
More Coding Interview Problems questions
- Problem: Count the substrings of length 3 in "xyzzaz" that contain three distinct characters.
- Problem: Min-cost climbing: cost = [10, 15, 20, 5, 1]. You may start at index 0 or 1, and from index i you can pay cost[i] to move up 1 or…
- Problem: Count the sequences of steps from {1, 2, 5} that sum to exactly 10 (the order of steps matters).
- Problem: A robot starts at (0, 0) facing north on an unbounded grid. Instructions: 'G' moves one step forward; 'L' turns 90° left; 'R'…
- Problem: Elevator starts at floor 0. Requests arrive in order for floors 3, 1, 4 (the elevator serves each request by going directly to…
- Problem: A traffic light cycles green for 30 s, then yellow for 5 s, then red for 25 s, starting at time 0 with green. How many whole…