Palindrome Checker
Difficulty: Easy · Topics: String, Two Pointers
Difficulty: Easy | Tags: String, Two Pointers
Description
Given a string s, determine if it is a palindrome after:
An empty string is considered a palindrome.
Implement:
isPalindrome(s) → boolean
Examples
Example 1:
Input: "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:
Input: "race a car"
Output: false
Example 3:
Input: " "
Output: true
Example 4:
Input: "Was it a car or a cat I saw?"
Output: true
Constraints
1 <= s.length <= 2 * 10^5sconsists only of printable ASCII characters.
Hints
Hint 1
Two-pointer approach: one from start, one from end. Skip non-alphanumeric characters. Compare characters case-insensitively.
Follow-up
- Can you check if the string can become a palindrome by removing at most one character?
---
## Testing & Edge Cases