Valid Palindrome

0Easy

Valid Palindrome

Given a string s, return true if it is a palindrome, considering only alphanumeric characters and ignoring case.

Rules:

  1. Ignore everything that isn't a letter or digit (spaces, punctuation).
  2. Comparisons are case-insensitive.

Key idea (Two Pointers):

  • Put left at the start and right at the end.
  • Skip non-alphanumeric characters under either pointer.
  • Compare the lowercased characters; on any mismatch return false.
  • Move both pointers inward until they meet.

Runs in O(n) time with O(1) extra space — no cleaned copy of the string is built.

JR

Jnaneshwara Reddy Satti

Builder · ClearCode

Hi — I'm a 21yo CS grad from India. I built ClearCode while recovering from a surgery, because I genuinely believe DSA should be visual, free, and accessible to everyone. No VC funding. No team. Just me, my laptop, and a lot of chai. ☕

If ClearCode helped you understand even one concept — consider supporting it. Every rupee keeps the servers running and new videos coming.

Support via Razorpay
Support ClearCode ☕