Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the length of the shortest substring of aabdecbcaeb that contains every character of abc (with multiplicity: at least one of each of a, b and c)?

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

Correct answer: A. 3

Expand the right boundary until all required letters are covered, then shrink from the left while coverage holds. Track coverage with counts, not a set, so repeated letters are handled.

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

Exams that ask this topic