Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Find the length of the shortest substring of "xaybzcxyabc" that contains all the letters a, b and c at least once.

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

Correct answer: A. 3

A two-pointer window that shrinks while all three letters remain covered finds the minimum window. Choosing the first complete window instead of the smallest one fails.

More Coding Interview Problems questions

Exams that ask this topic