Strings · Coding problem
Valid Palindrome
A free coding problem from the String Manipulation Basics skill. Read it here, then solve it in the app in Java or Python.
- Easy
- Coding problem
- Free
- Java and Python
The problem
Strip a line of text down to its letters and digits, ignore upper and lower case, and check whether what's left reads the same in both directions. Return whether it does.
Do it with two pointers and O(1) extra space, without building a cleaned copy of the string.
Input format
One line of text (it may contain spaces and punctuation).
Example
Input: Step on no pets!
Output: true
Without the spaces and punctuation it reads steponnopets.
Constraints
1 <= s.length <= 2 * 10^5sconsists of printable ASCII characters
How it's graded
- Run checks your code against the examples. Submit also runs a hidden suite in four groups - basic cases, edge cases, random inputs and performance tests at the size limit - and shows which groups pass, never the hidden inputs.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
- Once you pass, you see the approaches from brute force to optimal, and where your solution lands among them.
More problems in String Manipulation Basics
Solve it Valid Palindrome free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime