268. Longest Duplicate Substring (Length)

HardStringString

Given a string s, return the length of the longest substring that occurs at least twice in s (occurrences may overlap). If no duplicated substring exists, return 0.

Input: A quoted string s.

Output: Integer — length of the longest duplicated substring.

Examples

Example 1
Input: "banana"
Output: 3
Explanation: 'ana' appears twice.
Example 2
Input: "abcd"
Output: 0
Explanation: No duplicates.
Example 3
Input: "aaaa"
Output: 3
Explanation: 'aaa' appears twice.

Constraints

Asked by

GoogleAmazonMetaBloomberg
Solve this problem in the editor →