Explanation
In this program, we need to find the substring which has been repeated in the original string more than once.
In the above string, the substring bdf is the longest sequence which has been repeated twice.
Algorithm
- Define a string and calculate its length.
- Define a function for the longest common prefix that is, it takes two strings as arguments and determines the longest group of characters common in between them.
- Using the same function, we will compare original string will all its substrings. Then, first for loop compare all the substrings with all the other substrings till we find the longest repeating sequence.
- Storing the longest string in the variable lrs if the length of x is greater than lrs.
Input:
str = "acbdfghybdf"
Output:
Longest repeating sequence: bdf
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: