EASY NC#10 Blind #56 Two Pointers
125. Valid Palindrome
๐ Problem
Given a string s, return true if it is a palindrome, or false otherwise. A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
๐ง Visual Learning Aid
1 Model the input into the right structure
2 Choose the core technique and invariant
3 Execute step-by-step with a sample
4 Validate complexity and edge cases
JS/TS Refreshers
- โขArray methods (`push`, `pop`, `shift`, `slice`)
- โขObject/Map/Set usage patterns
- โขFunction parameter and return typing
- โขIn-place array updates
- โขSorted array traversal
- โขBoundary condition checks
Logical Thinking Concepts
- โขDefine invariants before coding
- โขCheck edge cases first (`[]`, single element, duplicates)
- โขEstimate time/space before implementation
- โขApply Two Pointers reasoning pattern
๐ก Approach
- โ Use two pointers from both ends
- โ Move pointers inward while matching
- โ Skip non-alphanumeric characters
- โ Ignore case
- โ Time: O(n), Space: O(1)
๐ ๏ธ Hints & Pitfalls
Hints
- โขUse two pointers from both ends
- โขMove pointers inward while matching
- โขSkip non-alphanumeric characters
Common Pitfalls
- โขIgnore case
- โขTime: O(n), Space: O(1)
๐งช Test Cases
Hidden tests on submit: 5
Test Case 1
Not run Input:
isPalindrome('A man, a plan, a canal: Panama'); Expected:
true Test Case 2
Not run Input:
isPalindrome(''); Expected:
true Test Case 3
Not run Input:
isPalindrome('a'); Expected:
true ๐ Code Editor
๐ค Output