Longest Repeating Substring

Medium

Description

Given a string s, find the length of the longest substring that appears at least twice in s. Overlapping occurrences are allowed.

Examples

Input:s = "banana"
Output:3
Explanation:

"ana" appears twice.

Input:s = "abcd"
Output:0
Explanation:

Edge case returning zero.

Input:s = "abcabc"
Output:3
Explanation:

The substring "abc" appears twice in the string - once at the beginning and once at the end.

Constraints

  • 1 ≤ s.length ≤ 2000
  • s consists of lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!