Merging Palindromes
Updated
Problem statement
From the letters of first, choose a multiset that can be rearranged into a palindrome. Do the same independently for second. Combine the two chosen multisets and rearrange them into one palindrome.
Return the longest palindrome obtainable this way. If several have maximum length, return the lexicographically smallest.
Function
mergingPalindromes(first: String, second: String) → StringExamples
Example 1
first = "aabbc"second = "ddefefq"return = "abdefcfedba"Use all available pairs and the smallest usable center. The result has maximum length and is lexicographically smallest among maximum-length results.
Example 2
first = "abc"second = "xyz"return = "a"No pair is available. Choose the smallest single character as the center.
Constraints
1 <= first.length, second.length <= 200000- Both strings contain lowercase English letters only.
More Zscaler interview questions
- Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
- Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
- Merge IntervalsPHONE SCREEN · Seen Jun 2024
- Sum of Divisors of the Array GCDPHONE SCREEN · Seen Jun 2024
- Asteroid CollisionONSITE INTERVIEW · Seen Sep 2024
- Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
- Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
- Longest Common Subsequence LengthONSITE INTERVIEW · Seen Jun 2024
- Run-Length EncodingONSITE INTERVIEW · Seen Jun 2024
- How Many Sentences? 🌿OA · Seen Mar 2024
Similar questions at other companies
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Valid Binary PrefixGoldman Sachs · OAGoldman Sachs interview questions
- Merging PalindromesAtlassian · OAAtlassian interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Remove K DigitsProcol · PHONE SCREEN
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
- Reorganize a StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Valid Parenthesis StringOracle · PHONE SCREENOracle interview questions
- Permutations IILinkedIn · PHONE SCREENLinkedIn interview questions