Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

In "abcabdabc", how many positions i >= 1 start an occurrence of the prefix "abc" (the first three characters)?

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

Correct answer: C. 1

Count starts i >= 1 where the length-3 window equals "abc". The window at index 3 is "abd" and does not match, while index 6 matches.

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

Exams that ask this topic