Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome With Non-Alphanumerics

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

Your question is Palindrome With Non-Alphanumerics. 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

OneTrust Privacy Management may receive user-entered text containing punctuation, spaces, and inconsistent capitalization. Given a string, determine whether it is a palindrome after removing every non-alphanumeric character and ignoring letter case.

Formal Specification

Implement is_palindrome(s), where s is a string containing ASCII letters, digits, spaces, and punctuation. Return True if the cleaned string reads identically from left to right and right to left. Return False otherwise. An empty cleaned string is considered a palindrome.

Use a two-pointer approach that compares characters from both ends without creating a separate cleaned string.

Constraints

  • 1 <= len(s) <= 2 * 10^5
  • s contains ASCII letters, digits, spaces, and punctuation
  • Comparison is case-insensitive
  • Non-alphanumeric characters are ignored

Function Signature

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