Data Structures & AlgorithmsHardAccenture · TCS NQT Digital

Problem: What is the length of the longest substring of "eceebaabbccbdeeabe" that contains at most 2 distinct characters?

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

Correct answer: A. 5

A sliding window with letter counts shrinks from the left only while more than two distinct letters are inside. Forgetting to delete zero-count letters makes the distinct-count test wrong.

More Coding Interview Problems questions

Exams that ask this topic