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?

  1. A. 5
  2. B. 3
  3. C. 4
  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

Exams that ask this topic