human
What is a code to longest repeating and non and the other steps required given the following:
Longest repeating and non | Returns the longest repeating non - overlapping substring in str.
building table in bottom - up manner.
( j - i ) > LCSRe [ i - 1 ] [ j - 1 ] to remove overlapping.
updating maximum length of the substring and updating the finishing index of the suffix.
If we have non - empty result , then insert all characters from first character to last character of string.
Driver Code"
Solution in Python:
assistant
#Here is code to longest repeating and non and the other steps required.
 def longestRepeatedSubstring ( str ) :
	n = len ( str )
	LCSRe = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]
	index = 0
	for i in range ( 1 , n + 1 ) :
		for j in range ( i + 1 , n + 1 ) :
			if ( str [ i - 1 ] == str [ j - 1 ] and LCSRe [ i - 1 ] [ j - 1 ] < ( j - i ) ) :
				LCSRe [ i ] [ j ] = LCSRe [ i - 1 ] [ j - 1 ] + 1
				if ( LCSRe [ i ] [ j ] > res_length ) :
					res_length = LCSRe [ i ] [ j ]
					index = max ( i , index )
			else :
				LCSRe [ i ] [ j ] = 0
	if ( res_length > 0 ) :
		for i in range ( index - res_length + 1 , index + 1 ) :
			res = res + str [ i - 1 ]
	return res
if __name__ == " _ _ main _ _ " :
	str = " geeksforgeeks "
	print ( longestRepeatedSubstring ( str ) )