← Two Pointers

Pattern Recognition Drill

#5 — Check palindrome string

Easy Arrays & Strings

The Problem

Given string s, return True if it's a palindrome.

What approach would you use?

Think about it before scrolling down.

Key Signals

Two Pointers

Compare s[l] and s[r], converge inward. First mismatch → not a palindrome. O(n) time, O(1) space.

Alt: Stack

Push first half, compare with second half popping. Same complexity but more code.

Common Trap

s == s[::-1] works in Python but uses O(n) extra space and doesn't show algorithmic thinking.

← #4 #6 →