Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome String Method

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

Your question is Palindrome String Method. 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

In QA checks for Finastra FusionFabric.cloud, reference strings may contain spaces, punctuation, and inconsistent capitalization. Implement a method that determines whether a string is a palindrome after ignoring non-alphanumeric characters and comparing letters without regard to case.

Formal Specification

Given a string s, return True if the sequence of alphanumeric characters reads identically from left to right and right to left after case normalization. Return False otherwise. An empty string, or a string containing no alphanumeric characters, is considered a palindrome.

Use Python's str.isalnum() to identify alphanumeric characters and str.lower() for case-insensitive comparison. The input is one string, and the output is a Boolean.

Constraints

  • 1 <= len(s) <= 2 * 10^5
  • s contains printable or Unicode characters
  • Comparison is case-insensitive
  • Non-alphanumeric characters must be ignored

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