PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates string manipulation, text sanitization, Unicode-aware character classification, and algorithmic complexity reasoning, and falls under the Coding & Algorithms domain.

  • Medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Determine sanitized palindrome in string

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: HR Screen

Write a function that determines whether a string is a palindrome after removing non-alphanumeric characters and ignoring case (e.g., punctuation, whitespace, symbols). Provide time and space complexity, and include tests covering edge cases with special characters and Unicode.

Quick Answer: This question evaluates string manipulation, text sanitization, Unicode-aware character classification, and algorithmic complexity reasoning, and falls under the Coding & Algorithms domain.

Write a function that determines whether a string is a palindrome after sanitizing it: remove every character that is not alphanumeric (drop punctuation, whitespace, and symbols) and compare letters case-insensitively. Return true if the remaining sequence reads the same forwards and backwards, and false otherwise. An empty result (a string with no alphanumeric characters) is considered a valid palindrome. Example 1: "A man, a plan, a canal: Panama" -> true (sanitizes to "amanaplanacanalpanama"). Example 2: "race a car" -> false (sanitizes to "raceacar"). Example 3: " " -> true (sanitizes to the empty string).

Constraints

  • 0 <= s.length <= 2 * 10^5
  • s consists of printable ASCII characters (and may include Unicode letters/digits).
  • A string with no alphanumeric characters is considered a palindrome.

Examples

Input: ("A man, a plan, a canal: Panama",)

Expected Output: True

Explanation: Sanitizes to 'amanaplanacanalpanama', which reads the same both ways.

Input: ("race a car",)

Expected Output: False

Explanation: Sanitizes to 'raceacar', which is not a palindrome.

Input: (" ",)

Expected Output: True

Explanation: Whitespace-only string sanitizes to the empty string, treated as a palindrome.

Input: ("",)

Expected Output: True

Explanation: Empty input has no characters to mismatch, so it is a palindrome.

Input: (".,",)

Expected Output: True

Explanation: Punctuation-only input sanitizes to the empty string, treated as a palindrome.

Input: ("0P",)

Expected Output: False

Explanation: Both characters are alphanumeric; lowercased it is '0p', and '0' != 'p', so it is not a palindrome.

Input: ("Madam",)

Expected Output: True

Explanation: Case-insensitive comparison: 'madam' is a palindrome.

Input: ("abBA",)

Expected Output: True

Explanation: Lowercased to 'abba', a palindrome.

Input: ("12321",)

Expected Output: True

Explanation: All-digit palindrome.

Input: ("No 'x' in Nixon",)

Expected Output: True

Explanation: Sanitizes to 'noxinnixon', which is a palindrome.

Hints

  1. First normalize the string: keep only alphanumeric characters and lowercase them.
  2. After normalizing, a palindrome check is just comparing the sequence to its reverse — or use two pointers moving inward.
  3. Decide your edge-case policy up front: the empty/whitespace-only/punctuation-only cases should all return true.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)