11062. Longest Repeating Substring

Given a string s, return the length of the longest substring that appears at least twice in s. The two occurrences may overlap. If no substring repeats, return 0.

Implement the following method:

class LongestRepeat {
    public int longestRepeat(String s) { }
}

Examples

Example 1:
new LongestRepeat().longestRepeat("abcde") -> 0
Explanation: No substring appears at least twice.

Example 2:
new LongestRepeat().longestRepeat("banana") -> 3
Explanation: "ana" occurs twice with overlap.

Example 3:
new LongestRepeat().longestRepeat("abcabca") -> 4
Explanation: "abca" appears twice (overlapping is allowed).

Example 4:
new LongestRepeat().longestRepeat("bbbbbb") -> 5
Explanation: "bbbbb" occurs at positions [0..4] and [1..5].

Constraints

- 1 <= s.length <= 2000
- s consists only of lowercase English letters 'a' to 'z'
- Answer is in the range [0, s.length - 1]




Please use Laptop/Desktop or any other large screen to add/edit code.