Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome With Cleanup

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

Your question is 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

An AstraZeneca data-quality utility receives a free-form study label. Determine whether the label is a palindrome after ignoring letter case and removing all non-alphanumeric characters.

A palindrome reads identically from left to right and right to left after normalization. For this problem, use Python's alphanumeric definition, so str.isalnum() determines whether a character is retained.

Formal Specification

Implement valid_palindrome(s).

  • Input: s, a string.
  • Output: Return True if the normalized string is a palindrome, otherwise return False.

Constraints

  • 0 <= len(s) <= 100,000
  • s may include letters, digits, whitespace, punctuation, and Unicode alphanumeric characters
  • Case differences must be ignored
  • The primary solution must use O(1) auxiliary space

Function Signature

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