#216HardStrings· Binary Search with Rolling Hash
Longest Repeated Log Segment
Input format
`log`: a string of lowercase English letters.
Output format
A single integer: the length of the longest substring that occurs at least twice.
Examples
Input: log = "banana"
Output: 3
The segment "ana" occurs at positions 1 and 3 (overlapping on the middle "a"). No segment of length 4 repeats.
Input: log = "abcdef"
Output: 0
All letters are different, so no segment appears twice and the answer is 0.
Input: log = "aaaaa"
Output: 4
"aaaa" starts at positions 0 and 1, so overlapping repeats count and the answer is 4.
Constraints
- 1 <= log.length <= 30000
- `log` consists of lowercase English letters.
- #string-hashing
- #rolling-hash
- #binary-search
- #strings