human
Give me a code to longest palindromic string possible by concatenating strings from a given array and the other steps required given the following:
Longest palindromic string possible by concatenating strings from a given array | Python3 program for the above approach.
Stores the distinct strings from the given array.
Insert the strings into set.
Stores the left and right substrings of the given string.
Stores the middle substring.
Traverse the array of strings.
Reverse the current string.
Checking if the is itself a palindrome or not.
Check if the reverse of the is present or not.
Append to the left substring.
Append to the right substring.
Erase both the strings from the set.
Print the left substring.
Print the middle substring.
Print the right substring.
Driver Code.
Function call"
Solution in Python:
assistant
#Here is code to longest palindromic string possible by concatenating strings from a given array and the other steps required.
 def max_len ( s , N , M ) :
	set_str = { }
	for i in s :
		set_str [ i ] = 1
	left_ans , right_ans = [ ] , [ ]
	mid = " "
	for i in range ( N ) :
		t = s [ i ]
		t = t [ : : - 1 ]
		if ( t == s [ i ] ) :
			mid = t
		elif ( t in set_str ) :
			left_ans . append ( s [ i ] )
			right_ans . append ( t )
			del set_str [ s [ i ] ]
			del set_str [ t ]
	for x in left_ans :
		print ( x , end = " " )
	print ( mid , end = " " )
	right_ans = right_ans [ : : - 1 ]
	for x in right_ans :
		print ( x , end = " " )
if __name__ == ' _ _ main _ _ ' :
	N = 4
	M = 3
	s = [ " omg " , " bbb " , " ffd " , " gmo " ]
	max_len ( s , N , M )