Closed MuhammadTausif closed 1 hour ago
def lps(self, str):
# code here
n = len(str)
dp = [0]*(n)
for i in range(1, n):
j = dp[i-1]
while j > 0 and str[j] != str[i]:
j = dp[j-1]
dp[i] = j + int(str[j] == str[i])
return dp[-1]
Longest Prefix Suffix
Link
Difficulty: Hard
Given a string of characters, find the length of the longest proper prefix which is also a proper suffix.
NOTE: Prefix and suffix can be overlapping but they should not be equal to the entire string.
Examples :
Constraints: