Prepin
Log in

Valid Palindrome

Approach / Explanation

The interview question Valid Palindrome requires you to assess whether a given string is a palindrome. A palindrome is defined as a string that reads identically forwards and backwards. In this case, you must disregard letter casing, special characters, and spaces. Your focus should be solely on alphanumeric characters to determine if the string qualifies as a palindrome. The input string may come in various languages, cases, and can include digits. Here are some tips to guide you in solving this problem: Begin by sanitizing the input string; eliminate any non-alphanumeric characters. Convert the sanitized string to lowercase to address case sensitivity. Next, verify if the sanitized string is identical to its reverse. If they are the same, return True to indicate that the string is a valid palindrome; otherwise, return False.

Suggested Answer

Consider the string A man, a plan, a canal: Panama . To determine if this string is a palindrome, follow these steps: First, eliminate all non-alphanumeric characters, resulting in: AmanaplanacanalPanama . Next, convert this to lowercase: amanaplanacanalpanama . Now, reverse the string and compare it to the cleaned version. The reversed string is amanaplanacanalpanama , which matches the original cleaned string. Therefore, the string qualifies as a palindrome, and we would return True.

Alternative Answer

Now, let’s examine a different example - "race a car" . After eliminating all non-alphanumeric characters, we obtain: raceacar . When converted to lowercase, it remains: raceacar . The reversed version of the string is racaecar . Since the reversed string does not match the original cleaned string, we determine that it is not a palindrome. Therefore, we would return False.

Question Details

Difficulty & Category

Medium

Companies

Deutsche Bank

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

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