Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome Check With Complexity

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

Your question is Palindrome Check With Complexity. 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

Decision Point's QA validation utilities need to identify whether an input string is a palindrome. Implement a function that compares the string case-insensitively while ignoring spaces, punctuation, and other non-alphanumeric characters.

Use a two-pointer approach so the function runs in linear time and uses constant auxiliary space. An empty string after normalization is considered a palindrome.

Formal Specification

  • Input: s, a string containing letters, digits, whitespace, and punctuation.
  • Output: Return True if the normalized string reads identically from left to right and right to left. Otherwise, return False.
  • Normalization: Keep only alphanumeric characters and compare them without regard to case.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains printable characters and Unicode alphanumeric characters
  • Comparison is case-insensitive
  • Non-alphanumeric characters are ignored
  • An empty normalized string is a palindrome

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