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?

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

Exams that ask this topic