Home
DSA Visualizer
Strings
Palindrome Check
Palindrome Check
A palindrome check tests whether a string reads the same forwards and backwards.
7 CHARS · 3 PAIRS
MATCH
L
0
1
2
3
4
5
R
6
'r' at 0 matches 'r' at 6. Move both pointers inwards.
Next
'a' at 1 matches 'a' at 5. Move both pointers inwards.
Word
Intuition
A palindrome reads the same forwards and backwards. We can verify this by comparing characters from the outside in. If any pair doesn't match, it's not a palindrome.
Concept
- Two Pointers: One at start, one at end.
- Comparison: Check if characters at pointers are equal.
- Termination: Stop when pointers meet or cross.
How it Works
Algorithm:
- Initialize
L = 0,R = n - 1. - While
L < R: - If
str[L] != str[R], return False. L++,R--.- Return True.
Step-by-Step Breakdown
Watch the visualization:
- See pointers move inwards.
- If a mismatch is found, the process stops immediately (Red).
- If pointers meet, it's a palindrome (Green).
When to Use
- Verifying palindromes.
- Checking symmetry in arrays/strings.
When NOT to Use
- N/A
How to Identify
"Is palindrome", "Read same forwards and backwards".
Applying for software engineering roles? Free, no sign-up:
