Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

What is the length of the shortest substring of "aabcbcdbca" that contains every distinct letter appearing in the whole string at least once?

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

Correct answer: D. 4

A two-pointer window with letter counts: expand until all distinct letters are present, then shrink from the left while they remain. The answer is the smallest such width. Counting the distinct letters gives only the lower bound.

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

Exams that ask this topic