Valid Palindrome I
String Simulation/Two Pointers
Problem
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
For example:
Thought Process
A palindrome is the same word spelt forwards and backwards
We have to convert uppercase letters to lowercase and disregard spaces and special characters
Solution
Key Points
Two pointers approach: one starting from the beginning and one at the end
Check whether each element is alphanumeric only, if so then convert to lowercase.
If either element in not alphanumeric, either increment or decrement either pointer, respectively
Time Complexity
Time: where n is the number of characters in the string
Space:
Last updated
Was this helpful?