Coders Crushby Napplied AI
Back to DSA Problems
EasyTwo Pointers

Is Palindrome II

Check palindrome with alphanumeric only

Solution Approach

Two pointers from both ends. Skip non-alphanumeric characters and compare in lowercase.

Implementation
def isPalindrome(s):
    left, right = 0, len(s) - 1
    while left < right:
        while left < right and not s[left].isalnum():
            left += 1
        while left < right and not s[right].isalnum():
            right -= 1
        if s[left].lower() != s[right].lower():
            return False
        left += 1
        right -= 1
    return True
Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)
Complexity
Time:O(n)
Space:O(1)
Asked at
FacebookApple
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless