data-structures · beginner · ~15 min

Recursive palindrome check

Check a palindrome from both ends inward.

Challenge

Implement:

int is_palindrome(const char *s);

Return 1 if s reads the same forwards and backwards, checked recursively; else 0.

Input format

A string.

Output format

1 if palindrome, else 0.

Constraints

Compare the outer pair, then recurse inward.

Starter code

#include <stddef.h>
/* Return 1 if s reads the same forwards and backwards, checked recursively; else 0. */
int is_palindrome(const char *s){ (void)s; return 0; }

Common mistakes

Not stopping when the two indices meet or cross.

Edge cases to handle

Empty and single-character strings are palindromes.

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.