basics · beginner · ~15 min
Two-pointer scan with character-class filtering.
Implement int is_palindrome(const char *s) that returns 1 if s reads the same forwards and backwards (ignoring case, ignoring all non-alphanumeric characters), or 0 otherwise.
is_palindrome("racecar") -> 1
is_palindrome("RaceCar") -> 1
is_palindrome("A man, a plan, a canal: Panama") -> 1
is_palindrome("hello") -> 0
is_palindrome("") -> 1 // empty is a palindrome by convention
is_palindrome(" ,.,. ") -> 1 // all-non-alnum collapses to empty
"Aa" is a palindrome (case-insensitive).Two-pointer scanning is the algorithmic backbone of dozens of string problems. The palindrome check is the smallest example that exercises ASCII case-folding and skipping irrelevant characters — exactly the moves you'll reuse in URL normalisation and CSV repair.
Null-terminated ASCII string.
1 (palindrome) or 0.
No allocations; no strrev.
int is_palindrome(const char *s) { /* TODO */ return 0; }
Allocating a 'cleaned' copy of the string (works but wastes memory). Forgetting that isalnum requires the argument cast to unsigned char to be safe.
Empty string; string of only punctuation; single character.
O(strlen(s)).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.