Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 B

What is the length of the longest substring of abcabdabcd that contains at most two distinct characters?

  1. A. 3
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: D. 2

A sliding window with a count map finds the longest stretch containing at most two letters. Restarting the window at each new letter is incorrect.

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

Exams that ask this topic