Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Palindrome Function

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

Your question is Python Palindrome Function. 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

SAS Viya validation tools may receive identifiers and messages with inconsistent capitalization or punctuation. Write a function that determines whether a string is a palindrome after converting letters to lowercase and ignoring all non-alphanumeric characters.

Formal Specification

Implement is_palindrome(s), where s is a Python string. Return True if the normalized string reads the same from left to right and right to left. Return False otherwise. A normalized string contains only lowercase letters and digits.

Use a two-pointer approach that compares characters from both ends without creating a reversed copy of the input.

Constraints

  • 1 <= len(s) <= 2 * 10^5
  • s contains printable ASCII characters
  • The string may contain letters, digits, spaces, and punctuation
  • 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