Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome or String Manipulation

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

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

The NatWest mobile app receives customer reference strings that may contain spaces, punctuation, and mixed casing. Write a function that determines whether the reference reads identically forwards and backwards after ignoring non-alphanumeric characters and letter casing.

Formal Specification

Implement is_palindrome(reference), where reference is a string. Return True if the normalized string is a palindrome, otherwise return False. Normalization removes every character that is not alphanumeric and compares letters without regard to case. The original string must not be modified.

Use a two-pointer approach that compares characters from the beginning and end while moving towards the center.

Constraints

  • 0 <= len(reference) <= 200,000
  • The input contains Unicode characters supported by Python string methods
  • Only alphanumeric characters are compared
  • An empty or fully non-alphanumeric string is considered a palindrome

Function Signature

def is_palindrome(reference):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output