Skills101
← All coding problems

Valid Palindrome

easyTwo Pointers+10 XPTime limit 2s

A sentence is a palindrome if, after removing everything except letters and digits and ignoring upper/lower case, it reads the same forwards and backwards. Example: A man, a plan, a canal: Panama → amanaplanacanalpanama → palindrome.

Input: one line s (printable ASCII; it does not start or end with a space).

Output: true or false.

Constraints: 1 ≤ length of s ≤ 2·10⁵.

Challenge: use two pointers from both ends, skipping non-alphanumeric characters — no need to build a cleaned copy.

Sample input 1

A man, a plan, a canal: Panama

Sample output 1

true

Sample input 2

race a car

Sample output 2

false

📖 Stuck? Learn the pattern

Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).

Loading editor…

Log in to run and submit your code — it's free.