Skip to content
Katabench
Try free

Valid Palindrome

Easy About 10 min Free, no account needed

Is the sentence a palindrome once punctuation and case are ignored?

The brief

Given a string s, return true if it reads the same forwards and backwards after keeping only letters and digits and ignoring case.

  • An empty string (or one with no alphanumeric characters) is a palindrome.
  • Digits participate: "0P" is not a palindrome.

The catch

The obvious approach builds a filtered, lower-cased copy and compares it with its reverse, two extra strings for a yes/no question. The challenge is to answer without allocating those copies. The hidden tests include the classic traps ("0P", punctuation-only strings).

Starter code

C#
using System;

public class Solution
{
    // TODO: return true when s is a palindrome over its alphanumeric characters, ignoring case.
    public bool IsPalindrome(string s)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

What it practices

Two pointers
Walk a sorted or symmetric sequence from both ends, or fast and slow, instead of checking every pair.
String processing
Parse, scan and match text character by character with correct edge cases.

Related katas