
Problem
Solution
Submissions
Palindrome Check
Certification: Basic Level
Accuracy: 75%
Submissions: 4
Points: 5
Write a JavaScript function to determine if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. For this problem, consider only alphanumeric characters and ignore case sensitivity.
Example 1
- Input: s = "racecar"
- Output: true
- Explanation:
- The string "racecar" contains only lowercase letters.
- Reading from left to right: r-a-c-e-c-a-r.
- Reading from right to left: r-a-c-e-c-a-r.
- Both directions give the same sequence, so it's a palindrome.
- The string "racecar" contains only lowercase letters.
Example 2
- Input: s = "A man, a plan, a canal: Panama"
- Output: true
- Explanation:
- The string contains letters, spaces, and punctuation.
- Considering only alphanumeric characters: "AmanaplanacanalPanama".
- Converting to lowercase: "amanaplanacanalpanama".
- This reads the same forwards and backwards, so it's a palindrome.
- The string contains letters, spaces, and punctuation.
Constraints
- 1 ≤ s.length ≤ 2 * 10^5
- s consists only of printable ASCII characters
- Consider only alphanumeric characters
- Ignore case sensitivity
- Time Complexity: O(n)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use two pointers approach: one from the beginning and one from the end
- Skip non-alphanumeric characters when moving the pointers
- Convert characters to lowercase for case-insensitive comparison
- Move pointers toward each other and compare characters
- If any pair doesn't match, return false
- If all pairs match, return true