Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Valid Palindrome

LeetCode #125Easy
Converging pointers · skip non-alphanumerics

Given a string, return true if it is a palindrome considering only alphanumeric characters and ignoring case.

Asked atMetaAmazonMicrosoft
step 1 / 9
R
a
c
e
c
a
r
[0][1][2][3][4][5][6][7]
Brute · clean + reverse
1clean ← lowercased alphanumerics of s
2return clean == reverse(clean)
state
  • cleaned"racecar"

line 1A string is a palindrome if it reads the same forwards and backwards, ignoring case and non-alphanumeric characters. Easiest idea: strip those out, lowercase, and compare to the reverse.