Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

String Palindrome With Cleanup

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

Your question is String Palindrome With Cleanup. 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

Meta Logistics Route Planner receives route labels containing spaces, punctuation, and special characters. Write a function that determines whether a label is a palindrome after removing every non-alphanumeric character and ignoring letter case.

Formal Specification

Implement is_palindrome(text), where text is a string. Return True if the normalized text reads identically from left to right and right to left; otherwise, return False. Normalization removes characters for which str.isalnum() is false and converts remaining letters to lowercase. An empty normalized string is considered a palindrome.

Constraints

  • 0 <= len(text) <= 10^5
  • text contains printable ASCII characters
  • Comparison is case-insensitive
  • All non-alphanumeric characters are ignored

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