Browse Curriculum

Palindrome Check

Visualize checking if a string reads the same forwards and backwards.

Alphanumeric only, max 12 chars
Ready to check Palindrome.
r
0
a
1
c
2
e
3
c
4
a
5
r
6

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:

  1. Initialize L = 0, R = n - 1.
  2. While L < R:
  3. If str[L] != str[R], return False.
  4. L++, R--.
  5. 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.