Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome Algorithm on Whiteboard

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

Your question is Palindrome Algorithm on Whiteboard. 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

Sandia National Laboratories systems such as Astra may process human-readable labels containing spaces, punctuation, and mixed capitalization. Write an algorithm that determines whether a string is a palindrome after normalization.

A normalized string is read from left to right after removing every character that is not an ASCII letter or digit and treating uppercase and lowercase letters as equivalent. Return True if the normalized string reads identically forward and backward; otherwise, return False.

Formal Specification

Implement is_palindrome(s), where s is a string of ASCII characters. Return a Boolean value. An empty normalized string is considered a palindrome.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains only ASCII letters, digits, spaces, and punctuation
  • Comparisons are case-insensitive
  • Non-alphanumeric characters are ignored
  • An empty normalized string is considered 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