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.
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
s aabbc
sddefefq
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 s have a length of
The six longest results in s have a length of
From the longest results for s and s 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 parameters:
string s: a string
string s: a string
Constraints
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
