Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

What is the length of the longest contiguous substring of "bbacbbcab" containing at most one letter 'a'?

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

Correct answer: C. 7

Slide a window that holds at most one 'a': 'bbacbbc' (indices 0–6) has one a and length 7, and no window of 8 qualifies. 9 is the whole string with two a's, 4 allows no 'a' at all ('cbbc'), and 2 counts the a's.

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

Exams that ask this topic