Problems/Two Pointers/Is Palindrome Valid
Two Pointers
easy

Is Palindrome Valid

This problem tests your ability to identify palindromes within strings, while also requiring you to handle and filter out irrelevant characters. It's a common interview question pattern that combines string manipulation with algorithmic thinking.

stringtwo-pointerspalindromealgorithmstring manipulation

Problem Statement

Given a string, determine if it is a near-palindrome. A near-palindrome is a string that reads the same forwards and backward after removing all non-letter characters (letters are defined as a-z and A-Z). Case should be ignored (e.g., 'a' is considered the same as 'A').

Example 1
Input: Madam, I'm Adam!
Output: True
After removing non-letter characters and converting to lowercase, the string becomes 'madamimadam', which is a palindrome.
Example 2
Input: Race fast, safe car!
Output: False
After removing non-letter characters and converting to lowercase, the string becomes 'racefastsafecar', which is not a palindrome.
Constraints
  • -The string can contain any ASCII characters.
  • -The string can be empty.
  • -You must ignore case.
  • -You must only consider letters (a-z, A-Z).

Brute Force Approach

The brute force approach would be like meticulously cleaning up a messy room character by character to see if the remaining letters form a palindrome. First, create a new string containing only the letters from the original string, converting each to lowercase. Then, reverse this new string and compare it to the original. If they are identical, the original string is a near-palindrome. The time complexity for this approach is O(n) since you iterate through the string multiple times, and the space complexity is also O(n) because you create a new string.

TimeO(n)
SpaceO(n)

Ready to practice?

Work through this problem with AI coaching and get real-time feedback

Practice This Problem