Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

In "xxyxxzxxx", what is the length of the longest substring that contains at most one character other than 'x'?

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

Correct answer: C. 6

Sliding window that tracks the count of non-'x' characters and allows at most one. The longest such window is "xxzxxx" around the z, of length 6.

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

Exams that ask this topic