Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture

Problem: The string "abracadabra" contains the substring "abra" at several positions. How many occurrences of "abra" are there (overlaps allowed)?

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

Correct answer: D. 2

'abra' starts at indices 0 and 7, giving two occurrences; the third 'abra' would need a fourth letter that does not exist after index 7.

More Coding Interview Problems questions

Exams that ask this topic