human
Rearrange string to obtain Longest Palindromic Substring | Function to rearrange the string to get the longest palindromic substring.
Stores the length of str.
Store the count of occurrence of each character.
Traverse the string , str.
Count occurrence of each character.
Store the left half of the longest palindromic substring.
Store the right half of the longest palindromic substring.
Traverse the array , hash [ ].
Append half of the characters to res1.
Append half of the characters to res2.
reverse string res2 to make res1 + res2 palindrome.
Store the remaining characters.
Check If any odd character appended to the middle of the resultant string or not.
Append all the character which occurs odd number of times.
If count of occurrence of characters is odd.
Driver Code"
Solution in Python:
 ... Write me a code to rearrange string to obtain Longest Palindromic Substring and the other steps required?
assistant
#Here is code to rearrange string to obtain Longest Palindromic Substring and the other steps required.
 def longestPalinSub ( st ) :
	N = len ( st )
	hash1 = [ 0 ] * 256
	for i in range ( N ) :
		hash1 [ ord ( st [ i ] ) ] += 1
	res1 = " "
	res2 = " "
	for i in range ( 256 ) :
		for j in range ( hash1 [ i ] // 2 ) :
			res1 += chr ( i )
		for j in range ( ( hash1 [ i ] + 1 ) // 2 , hash1 [ i ] ) :
			res2 += chr ( i )
	p = list ( res2 )
	p . reverse ( )
	res2 = ' ' . join ( p )
	res3 = " "
	f = False
	for i in range ( 256 ) :
		if ( hash1 [ i ] % 2 ) :
			if ( not f ) :
				res1 += chr ( i )
				f = True
			else :
				res3 += chr ( i )
	return ( res1 + res2 + res3 )
if __name__ == " _ _ main _ _ " :
	st = " geeksforgeeks "
	print ( longestPalinSub ( st ) )