Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome Check with Cleanup

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

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

BCG X may process text from reports and client communications where punctuation, spaces, and capitalization should not affect comparisons. Given a string, determine whether it is a palindrome after ignoring every non-alphanumeric character and treating uppercase and lowercase letters as equal.

Formal Specification

Implement is_palindrome(s), where s is a string. Return True if the filtered string reads identically from left to right and right to left; otherwise, return False. The filtered string contains only letters and digits. An empty filtered string is considered a palindrome.

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

Constraints

  • 1 <= len(s) <= 2 * 10^5
  • s contains printable ASCII characters
  • Letters are compared case-insensitively
  • Digits are valid alphanumeric characters

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