Prepin
Log in

Given two strings of the same length, assess whether it's feasible to create a palindrome by splitting them in half.

Approach / Explanation

This algorithm-based question requires you to find out if two strings of the same length can be split in half to create a palindrome. A palindrome is defined as a word, phrase, number, or sequence of characters that reads identically forwards and backwards, like 'madam' or 'abba'. The challenge involves dividing the given strings in half and then combining those halves to form a palindrome. To address the question, you should keep in mind a few important considerations: Equal Length : Since the strings are of the same length, they can be evenly divided in the center. Creating a Palindrome : It's essential to understand how a palindrome is structured: it must read the same from both the left and the right. Therefore, you need to ensure that the halves of the strings, when assembled together, create a sequence of characters that meets this criterion.

Suggested Answer

To clarify the situation, let's examine an example involving two strings: abc and cba . These strings have the same length and are reflections of one another. If you split the strings in the middle and merge them, you arrive at: ab + c + ba , resulting in abcba , which is a palindrome. This shows that, in this specific instance, it's feasible to create a palindrome by halving the strings.

Alternative Answer

Let’s examine another instance where the two strings are laval and avall . If you divide both strings into lava and l for the first string, and aval and l for the second string, you'll notice that the latter part of both strings is identical ( l ), while the first part of the first string creates a palindrome ( laval ). By merging the two halves, the resulting string is indeed a palindrome. This demonstrates that it is feasible to create a palindrome from two strings of the same length by splitting them in half.

Question Details

Difficulty & Category

Medium
algorithms

Companies

Google

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.