Question: 2 . Merging Palindromes Given two strings, identify all palindromes that can be formed from each string's letters. Select one palindrome from each set that.

2. Merging Palindromes
Given two strings, identify all palindromes that can be formed from each string's letters. Select one palindrome from each set that. when combined and rearranged, creates the longest possible palindrome. If multiple palindromes of this minimum length exist. return the alphabetically smallest one.
Example
s1= aabbc
s2=ddefefq
All of the letters of the first string can make a palindrome. The choices using all letters are (abcha, bacab].
All of the letters of the second string can make a palindrome. The choices using all letters are [defqfed, dfeqefd, edfqfde, efdqdfe, fdeqedf, fedqdef].
The two longest results in s1 have a length of 5.
The six longest results in s2 have a length of 6.
From the longest results for s1 and s2, merge the two that form the lowest merged palindrome, alphabetically. In this case, choose abcba and defqfed. The two palindromes can be combined to form a single palindrome if either the cor the qis discarded. The alphabetically smallest combined palindrome is abdefcfedba.
Function Description
Complete the function merge Palindromes in the editor below. The function must return a string.
mergePalindromes has the following parameter(s):
string s1: a string
string s2: a string
Constraints
12/51/105
14/2/105

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!