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 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
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.
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
- Longest Palindromic Substring (Length) Medium Free How long is the longest palindrome hiding in the string?
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.