Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft

What is the length of the smallest substring of "baddcacdabcbd" that contains every distinct character of the string at least once? (Variable sliding window with a count map.)

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

Correct answer: A. 4

The string uses 4 distinct letters. Expand right until all are present, then shrink from the left while they remain; the smallest such window has length 4.

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

Exams that ask this topic