101 Logo
onenoughtone

Problem Statement

Palindrome Checker

A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).

Write a function that checks if a given string is a palindrome. The function should return true if the string is a palindrome, and false otherwise.

Examples

Example 1:

Input: "racecar"
Output: true
Explanation: The word 'racecar' reads the same forward and backward.

Example 2:

Input: "hello"
Output: false
Explanation: The word 'hello' does not read the same backward (it would be 'olleh').

Example 3:

Input: "A man, a plan, a canal: Panama"
Output: true
Explanation: Ignoring spaces, punctuation, and capitalization, it reads the same forward and backward.

Constraints

  • The input string will only contain printable ASCII characters.
  • The function should ignore spaces, punctuation, and capitalization when determining if a string is a palindrome.
  • An empty string is considered a palindrome.

Problem Breakdown

To solve this problem, we need to:

  1. We need to handle non-alphanumeric characters by skipping them during comparison.
  2. Case insensitivity is important, so we should convert characters to the same case before comparing.
  3. The two-pointer technique is efficient for this problem, using O(n) time and O(1) space.
  4. Alternatively, we can clean the string first and then check if it equals its reverse.
ProblemSolutionCode
101 Logo
onenoughtone