Medium · Tries

Longest Repeated Substring

Given a string str, return its longest substring that occurs at least twice (the two occurrences may overlap), or "" if no substring repeats; when several repeated substrings share the maximum length, any one of them is accepted.

Examples

Example 1

{
  "str": "abab"
}

Output: "ab"

Example 2

{
  "str": "banana"
}

Output: "ana"

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Tries problems