Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Palindrome Ignoring Symbols

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

Your question is Validate Palindrome Ignoring Symbols. 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

At Stripe, you need to validate whether a user-entered string reads the same forward and backward when punctuation, spaces, and other non-alphanumeric characters are ignored. Write an algorithm that returns whether the cleaned string is a palindrome.

Formal Specification

Implement a function that takes a single string s and returns a boolean:

  • Input: s — a string containing letters, digits, spaces, and special characters
  • Output: True if the string is a palindrome after removing all non-alphanumeric characters and ignoring letter case; otherwise False

Constraints

  • 0 <= len(s) <= 2 * 10^5
  • s consists of letters, digits, spaces, and printable special characters
  • Ignore all non-alphanumeric characters during comparison
  • Treat uppercase and lowercase letters as equal

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