human
Longest Common Substring in an Array of Strings | function to find the stem ( longestcommon substring ) from the string array.
Determine size of the array.
Take first word from array as reference.
generating all possible substrings of our reference string arr [ 0 ] i . e s.
Check if the generated stem is common to all words.
If current substring is present in all strings and its length is greater than current result.
Driver Code.
Function call"
Solution in Python:
 ... What is a code to longest Common Substring in an Array of Strings and the other steps required?
assistant
#Here is code to longest Common Substring in an Array of Strings and the other steps required.
 def findstem ( arr ) :
	n = len ( arr )
	s = arr [ 0 ]
	l = len ( s )
	res = " "
	for i in range ( l ) :
		for j in range ( i + 1 , l + 1 ) :
			stem = s [ i : j ]
			k = 1
			for k in range ( 1 , n ) :
				if stem not in arr [ k ] :
					break
			if ( k + 1 == n and len ( res ) < len ( stem ) ) :
				res = stem
	return res
if __name__ == " _ _ main _ _ " :
	arr = [ " grace " , " graceful " , " disgraceful " , " gracefully " ]
	stems = findstem ( arr )
	print ( stems )