Palindrome checker
Determine whether a phrase reads the same forward and backward while ignoring spaces, punctuation, and letter case.
Course progress
Problem 4 of 100
Example → approach → runnable solution
Worked example
See the problem in action
Trace a concrete input through to the verified result.
Example input
text = "Never odd or even"
Expected output
True
What is happening?
Ignoring spaces and letter case produces neveroddoreven. Reading those letters from either end gives the same sequence, so the result is true.
Solution strategy
Build the right mental model
Move pointers inward from both ends. Skip non-alphanumeric characters and compare the remaining characters case-insensitively.
Core concepts
strings · two pointers
Complexity
Time O(n), space O(1).
Runnable solution
Learn from working code
Compare languages, copy the code, or open it in the compiler.
Complete C# solution for palindrome
using System;
class Program
{
static bool IsPalindrome(string text)
{
int left = 0;
int right = text.Length - 1;
while (left < right)
{
if (!char.IsLetterOrDigit(text[left])) { left++; continue; }
if (!char.IsLetterOrDigit(text[right])) { right--; continue; }
if (char.ToLowerInvariant(text[left]) != char.ToLowerInvariant(text[right])) return false;
left++;
right--;
}
return true;
}
static void Main()
{
Console.WriteLine(IsPalindrome("Never odd or even"));
}
}Knowledge check
Questions students often ask
What is the main idea behind palindrome checker?
Move pointers inward from both ends. Skip non-alphanumeric characters and compare the remaining characters case-insensitively.
What is the time and space complexity of this solution?
Time O(n), space O(1).
Do all language tabs solve the same problem?
Yes. Every program uses the same example and produces the verified output shown on this page. The syntax and a few language-specific data structures differ.