Solve the longest repeating substring problem in O(n^2) using KMP partial match function.