Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Two-Pointer Palindrome Check

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

Your question is Two-Pointer Palindrome Check. 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

Honeywell Forge may receive asset labels and operator-entered identifiers with inconsistent capitalization and punctuation. Given a string, determine whether it is a palindrome after ignoring non-alphanumeric characters and treating uppercase and lowercase letters as equal.

Use an optimized two-pointer approach. The solution should scan inward from both ends without constructing a second normalized string.

Formal Specification

Implement is_palindrome(s), where s is a Python string. Return True if the normalized string reads identically from left to right and right to left; otherwise return False. A normalized string contains only alphanumeric characters, compared case-insensitively. An empty normalized string is considered a palindrome.

Constraints

  • 0 <= len(s) <= 100000
  • The input may contain Unicode letters and digits, whitespace, punctuation, and symbols
  • Comparisons are case-insensitive
  • The normalized string may be empty

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