LeetEye LeetEye
Cheat Sheet

Two Pointers Cheat Sheet

Quick reference for coding interviews. Bookmark this page!

What is Two Pointers?

Learn to solve problems efficiently using the two-pointer technique.

Trigger Words

When you see these in a problem, think Two Pointers:

valid palindrome two-pointers two sum ii - input array is sorted 3sum container with most water trapping rain water

Template Code

def isPalindrome(s: str) -> bool:
    left, right = 0, len(s) - 1
    
    while left < right:
        # Skip non-alphanumeric from left
        while left < right and not s[left].isalnum():
            left += 1
        # Skip non-alphanumeric from right
        while left < right and not s[right].isalnum():
            right -= 1
        
        # Compare characters (case-insensitive)
        if s[left].lower() != s[right].lower():
            return False
        
        left += 1
        right -= 1
    
    return True

Complexity

Typical Time O(n)
Typical Space O(1)

Common Variations

  • Basic Two Pointers
  • Two Pointers with constraints
  • Optimized Two Pointers

Practice Problems

See all Two Pointers problems →

Practice Two Pointers

Learn to recognize patterns instantly with interactive MCQs.

Download LeetEye Free
Practice in LeetEye