Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the length of the longest substring of "eceeebbaccbbaaceddccc" that contains AT MOST two distinct letters?

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

Correct answer: B. 5

Sliding window with a letter-count map: when more than two distinct letters appear, shrink from the left until only two remain. Requiring EXACTLY two distinct letters is a stricter condition and gives a smaller answer here.

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

Exams that ask this topic