FastPrepMerging Palindromes
Problems/Merging Palindromes

Merging Palindromes

Zscaler logoZscaler● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report keeps the goal of the longest, lexicographically smallest palindrome built from two strings. It leaves out the exact rules for choosing the pair and the center, the interface, and the limits. Our version is about 72% the same as the reported question.

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) → String

Examples

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

Interview reports that mention this question

  • Zscaler SDE C++ and OS Rounds: 7 Experiences (Part 2 of 6)
  • Zscaler Campus SDE Interviews: 37 Experiences (Part 1 of 6)

Zscaler interview experiences

  • Zscaler Campus Drive Interviews: 4 Experiences (Part 6 of 6)
  • Zscaler Java, QA and Cloud Rounds: 8 Experiences (Part 5 of 6)
  • Zscaler UI and DevTest Rounds: 8 Experiences (Part 4 of 6)
  • Zscaler Intern, QA and SRE Rounds: 7 Experiences (Part 3 of 6)
All Zscaler interview questionsSee Zscaler hiring insights
Saved
class Solution {
    public String mergingPalindromes(String first, String second) {
      // write your code here
    }
}
Checking account…