Palindrome Check

beginner
1,230 views756 solved
stringtwo-pointers

Problem Description

Write a function that checks if a given string is a palindrome.

A palindrome is a string that reads the same forwards and backwards, ignoring spaces, punctuation, and capitalization.

Example:

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

Output: true

Input: "race a car"

Output: false

Constraints:

- 1 <= s.length <= 2 * 10^5

- s consists only of printable ASCII characters.

JavaScriptPress Ctrl+Enter to run tests
Loading editor...

Test Cases

Test 1

Famous palindrome phrase

Input:[ "A man, a plan, a canal: Panama" ]
Expected:true
Test 2

Not a palindrome

Input:[ "race a car" ]
Expected:false
Test 3

Empty/whitespace string

Input:[ " " ]
Expected:true

+ 1 hidden test

ASleekGeek - Beyond the Code. Building the Future.