Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

Let t = "ABCC" (its letters may repeat). What is the length of the shortest substring of "ADOBECODEBANCXY" that contains every letter of t with at least the required multiplicity?

  1. A. 8
  2. B. 4
  3. C. 9
  4. D. 7

Correct answer: A. 8

Two pointers with a need-counter: expand right until all demands are met, then shrink left while still valid, recording the smallest width. Ignoring multiplicities (checking only distinct letters) finds a shorter window that fails the count requirement.

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

Exams that ask this topic