Neural Mastery
← Practice
Valid Palindromeeasy

Valid Palindrome

easy Coding Interview Patterns 10–15 min

NumPy allowed · plain Python earns 10 bonus points

Interactive
Two Pointers & Sliding Window, Step by Step
Pattern
1
L
2
3
4
6
R
arr[L]=1 + arr[R]=6 = 7 vs target 6 -> too big, move R left
Step 1 / 3
Both modes run the exact algorithm described on the linked practice problem, one real step at a time -- not a pre-rendered animation. Edit the input and every step recomputes live.

Implement the two-pointer palindrome check -- inward convergence from both ends while skipping non-alphanumeric characters and normalizing case in O(n) time and O(1) extra space.

Related Skills

Task

Implement is_palindrome(s): return True if after filtering out all non-alphanumeric characters and converting all letters to lowercase, the string reads the same forwards and backwards.

Function Signature

is_palindrome(s: str) -> bool

Examples

Example 1: Classic Panama Palindrome
Input: s = 'A man, a plan, a canal: Panama'
Output: True
Example 2: Not a Palindrome
Input: s = 'race a car'
Output: False

Constraints

  • Libraries are allowed; a plain-Python solution earns 10 bonus points.
  • 1 <= len(s) <= 2 * 10^5.
  • s consists only of printable ASCII characters.
Python3Saved ✓
def is_palindrome(s: str) -> bool:
"""Return True if s is a palindrome considering only alphanumeric
characters and ignoring case, False otherwise."""
# Your implementation here
pass

Case 1: Classic Panama Palindrome
Input: s = 'A man, a plan, a canal: Panama'
Expected: True
Case 2: Not a Palindrome
Input: s = 'race a car'
Expected: False