Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

In the string "bbaacbbaaac", what is the length of the shortest contiguous substring that contains at least three letters 'a'?

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

Correct answer: C. 3

Sliding window over positions of 'a': the minimum is the span of any three consecutive 'a' positions. Taking the first valid window rather than the shortest is the usual error.

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

Exams that ask this topic