Given a string of no more than 255 characters, find a function that returns the longest recurring substring. An example would be:


where the longest recurring sub-string is aabba. I would preffer the answer in C/C++ as they are the only languages I know. The algorithm should be as fast as possible.

  • 1
    \$\begingroup\$ What is recurring string ? same characters ? Why is there a C++ language limitation ? \$\endgroup\$
    – Optimizer
    Feb 6, 2015 at 11:34
  • \$\begingroup\$ I know only C/C++, sorry, substring not string, a recurring substring is a substring that appears more than once. \$\endgroup\$
    – Sherpinsky
    Feb 6, 2015 at 11:36
  • \$\begingroup\$ Ah. It would probably be better to give out some examples. Also, this is PPCG so you need to have a winning criteria . Do you want the shortest code ? faster algorithm ? most popular code ? Also, language specific questions are frowned upon here, so it would be better if you can remove that restriction and just ask in the question that you are specifically looking for C++ answer \$\endgroup\$
    – Optimizer
    Feb 6, 2015 at 11:42
  • 2
    \$\begingroup\$ Winning criteria please :) \$\endgroup\$
    – Optimizer
    Feb 6, 2015 at 11:45
  • \$\begingroup\$ Are overlapping occurrences counted as distinct? For example, in the string aabbaabba, is the substring aabba recurring? \$\endgroup\$
    – Zgarb
    Feb 6, 2015 at 11:53


Browse other questions tagged or ask your own question.