Recall & Review
beginner
What is a palindrome?
A palindrome is a word, number, phrase, or sequence that reads the same backward as forward, ignoring spaces, punctuation, and capitalization.
Click to reveal answer
beginner
How can you check if a string is a palindrome using two pointers?
Use two pointers: one at the start and one at the end of the string. Move both pointers towards the center, comparing characters. If all pairs match, it's a palindrome.
Click to reveal answer
beginner
Why do we ignore spaces and punctuation when detecting palindromes?
Ignoring spaces and punctuation helps focus on the actual letters or digits, making the palindrome check meaningful for phrases and sentences, not just single words.
Click to reveal answer
intermediate
What is the time complexity of checking a palindrome in a string of length n?
The time complexity is O(n) because each character is checked at most once when comparing pairs from start and end.
Click to reveal answer
beginner
Show a simple Python code snippet to check if a string is a palindrome ignoring case and non-alphanumeric characters.
import re
def is_palindrome(s: str) -> bool:
s = re.sub(r'[^a-zA-Z0-9]', '', s).lower()
return s == s[::-1]Click to reveal answer
Which of the following strings is a palindrome?
✗ Incorrect
The word 'racecar' reads the same backward and forward.
What is the main idea behind the two-pointer technique for palindrome detection?
✗ Incorrect
Two pointers start at opposite ends and move inward comparing characters.
Why do we convert the string to lowercase before checking palindrome?
✗ Incorrect
Lowercasing ensures 'A' and 'a' are treated the same.
What is the time complexity of palindrome detection using the two-pointer method?
✗ Incorrect
Each character is checked once, so time is linear.
Which Python method helps to reverse a string easily?
✗ Incorrect
The slice notation s[::-1] returns the reversed string.
Explain how to detect if a string is a palindrome using the two-pointer technique.
Think about checking characters from both ends moving inward.
You got /5 concepts.
Describe why preprocessing (like removing spaces and punctuation) is important in palindrome detection for sentences.
Consider how phrases differ from single words.
You got /4 concepts.