Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: The string "banana" has its longest repeated substring (a substring occurring at least twice, overlaps allowed) of length L. What is L?

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

Correct answer: B. 3

Test each length from the largest down, checking whether any substring repeats (overlaps allowed). The repeat 'ana' overlaps itself inside 'banana', which is why overlaps must be permitted.

More Coding Interview Problems questions

Exams that ask this topic