Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome Detection Coding

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Palindrome Detection Coding. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

During LTTS quality engineering validation, test identifiers may contain spaces, punctuation, and mixed case. Write a function that returns whether an identifier is a palindrome after ignoring non-alphanumeric characters and letter case.

A palindrome reads identically from left to right and right to left after normalization. For example, "No lemon, no melon" is a palindrome because its normalized form is "nolemonnomelon".

Formal Specification

Implement is_palindrome(text).

  • Input: text, a string containing letters, digits, spaces, and punctuation.
  • Output: A boolean. Return true when the normalized string is a palindrome, otherwise return false.

Do not build a separate normalized string. Compare characters in place using two pointers.

Constraints

  • 0 <= len(text) <= 100,000
  • text contains printable ASCII characters
  • Comparison ignores case and non-alphanumeric characters
  • Empty and punctuation-only strings return true

Function Signature

def is_palindrome(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output