Data Structures & AlgorithmsHardGATE CS · ICPC regional

What is the length of the longest substring of aabccbb that can be made into a string of one repeated letter by replacing at most 2 characters?

  1. A. 4
  2. B. 5
  3. C. 6
  4. D. 7

Correct answer: B. 5

The classic window condition is length minus the maximum frequency in the window being at most k. The window never needs to shrink for a longer valid window to appear.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic