Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

23. Valid Palindrome

EasyDay 7 of 60Two Pointers

A phrase is a palindrome if, after converting all uppercase letters to lowercase and removing every character that is not a letter or a digit, it reads the same forwards and backwards. Given a string s, return true if it is a palindrome, otherwise false.

Example 1
Input: s = "A man, a plan, a canal: Panama"
Output: true
After cleaning it becomes "amanaplanacanalpanama", which reads the same both ways.
Example 2
Input: s = "race a car"
Output: false
Cleaned it is "raceacar", which is not a palindrome.
Constraints
  • 1 <= s.length <= 2 * 10^5
  • s contains printable ASCII characters only
Hints
Frequently asked at: Meta, Microsoft, Amazon, TCS, Infosys
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min