Longest Repeating Substring - Problem
Given a string s, return the length of the longest repeating substring. If no repeating substring exists, return 0.
A repeating substring is a substring that occurs at least twice in the string.
Input & Output
Example 1 — Basic Repeating Pattern
$
Input:
s = "abcabc"
›
Output:
3
💡 Note:
The substring "abc" appears twice: at positions 0-2 and 3-5, so the longest repeating substring has length 3
Example 2 — Single Character Repetition
$
Input:
s = "aabaaaba"
›
Output:
4
💡 Note:
The substring "aaba" appears at positions 0-3 and 4-7, so the longest repeating substring has length 4
Example 3 — No Repetition
$
Input:
s = "abcdef"
›
Output:
0
💡 Note:
No substring appears more than once, so return 0
Constraints
- 1 ≤ s.length ≤ 1000
- s consists of lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code