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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Tries problems