Home
DSA Course
Strings
Palindrome Check
Palindrome Check
Visualize checking if a string reads the same forwards and backwards.
Alphanumeric only, max 12 chars
Ready to check Palindrome.
r
0a
1c
2e
3c
4a
5r
6Intuition
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".
Frequently Asked Questions
What is Palindrome Check?
Visualize checking if a string reads the same forwards and backwards.
What is the time complexity of Palindrome Check?
The time complexity is: Best case varies, Average case O(N), Worst case varies. Space complexity is varies.
