Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture

Problem: The string "aaaaa" is split into non-overlapping occurrences of "aa" from left to right (greedily taking each match). How many occurrences are found?

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

Correct answer: A. 2

Non-overlapping greedy matching jumps past each match, so five letters give two matches with one letter left over. Overlapping search would find four.

More Coding Interview Problems questions

Exams that ask this topic