Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Palindrome Runtime Optimization
00:00
5 left

Palindrome Runtime Optimization

EasyPython

Problem

TRADER Corporation may need to validate normalized text in listing titles or search inputs. Given a string, determine whether it is a palindrome after ignoring case and removing all non-alphanumeric ASCII characters.

Return True if the remaining characters read identically from left to right and right to left. Return False otherwise.

Formal Specification

Implement is_palindrome(text), where text is a string and the return value is a boolean. Treat ASCII letters case-insensitively. Digits remain unchanged, and spaces, punctuation, and other non-alphanumeric characters are ignored.

You should optimize the solution for linear runtime and constant auxiliary space by comparing characters from both ends while moving toward the center.

Constraints

  • 0 <= len(text) <= 100,000
  • text contains printable ASCII characters
  • An empty string is considered a palindrome
  • Do not modify the input string

Function Signature

def is_palindrome(text):
Interviewer

Your question is Palindrome Runtime Optimization. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.