Talentd
FleetCode

1062. Longest Repeating Substring

Medium63.4% acceptance4 companiesPremium elsewhere, free here

Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.

Example 1:

Input: s = "abcd"
Output: 0
Explanation: There is no repeating substring.

Example 2:

Input: s = "abbaba"
Output: 2
Explanation: The longest repeating substrings are "ab" and "ba", each of which occurs twice.

Example 3:

Input: s = "aabcaabdaab"
Output: 3
Explanation: The longest repeating substring is "aab", which occurs 3 times.

Constraints:

  • 1 <= s.length <= 2000
  • s consists of lowercase English letters.

Asked at 4 companies

Hints open one at a time

Hint 1
Generate all substrings in O(N^2) time with hashing.
Hint 2
Choose those hashing of strings with the largest length.
43:45
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
"abcd"
Input
"abbaba"
Input
"aabcaabdaab"
Your code is saved on this device.Solution