basics · beginner · ~15 min
Two-pointer scan with character-class filtering.
Check whether a string reads the same forwards and backwards, ignoring case and any non-alphanumeric characters.
Implement int is_palindrome(const char *s) that returns 1 if s is a palindrome and 0 otherwise. Compare only alphanumeric characters (isalnum), skip everything else, and treat upper- and lowercase as equal. Use a two-pointer scan from both ends inward — do not build a cleaned copy.
A NUL-terminated ASCII string s.
Returns 1 if s is a palindrome under those rules, otherwise 0.
is_palindrome("racecar") -> 1
is_palindrome("RaceCar") -> 1 (case-insensitive)
is_palindrome("A man, a plan, a canal: Panama") -> 1
is_palindrome("hello") -> 0
is_palindrome("") -> 1 (empty, by convention)
is_palindrome(" ,.,. ") -> 1 (no alnum chars)
strrev.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.
A NUL-terminated ASCII string s.
1 if s is a palindrome (case- and punctuation-insensitive), otherwise 0.
s is null-terminated string to test.
int is_palindrome(const char *s) { /* TODO */ return 0; }
Comparing case-sensitive characters or indexing before start of string.
Empty string, single character, mixed-case palindromes with punctuation.
O(strlen(s)).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.