Challenge - 5 Problems
Palindrome Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Two Pointer Palindrome Check
What is the output of the following C# code that checks if a string is a palindrome ignoring non-alphanumeric characters and case?
DSA C#
using System; public class Solution { public static bool IsPalindrome(string s) { int left = 0, right = s.Length - 1; while (left < right) { while (left < right && !Char.IsLetterOrDigit(s[left])) left++; while (left < right && !Char.IsLetterOrDigit(s[right])) right--; if (Char.ToLower(s[left]) != Char.ToLower(s[right])) return false; left++; right--; } return true; } public static void Main() { string input = "A man, a plan, a canal: Panama"; Console.WriteLine(IsPalindrome(input)); } }
Attempts:
2 left
💡 Hint
Focus on how non-alphanumeric characters are skipped and case is ignored.
✗ Incorrect
The code uses two pointers moving inward, skipping non-alphanumeric characters and comparing lowercase characters. The input is a well-known palindrome phrase ignoring punctuation and case, so the output is True.
❓ Predict Output
intermediateResult of Palindrome Check on Non-Palindrome String
What will the output be when running the palindrome check code on the string "race a car"?
DSA C#
using System; public class Solution { public static bool IsPalindrome(string s) { int left = 0, right = s.Length - 1; while (left < right) { while (left < right && !Char.IsLetterOrDigit(s[left])) left++; while (left < right && !Char.IsLetterOrDigit(s[right])) right--; if (Char.ToLower(s[left]) != Char.ToLower(s[right])) return false; left++; right--; } return true; } public static void Main() { string input = "race a car"; Console.WriteLine(IsPalindrome(input)); } }
Attempts:
2 left
💡 Hint
Check character comparisons carefully after skipping spaces.
✗ Incorrect
The string "race a car" is not a palindrome when ignoring spaces and case because the characters at the ends do not match after skipping.
🧠 Conceptual
advancedWhy Two Pointers Work for Palindrome Checking
Why is the two-pointer technique effective for checking if a string is a palindrome?
Attempts:
2 left
💡 Hint
Think about how palindrome means the string reads the same forwards and backwards.
✗ Incorrect
Two pointers start at the beginning and end of the string and move inward, comparing characters. This directly checks the palindrome property of symmetry.
🔧 Debug
advancedIdentify the Bug in Palindrome Code
What is the bug in this palindrome checking code snippet?
DSA C#
public static bool IsPalindrome(string s) { int left = 0, right = s.Length - 1; while (left <= right) { if (Char.ToLower(s[left]) != Char.ToLower(s[right])) return false; left++; right--; } return true; }
Attempts:
2 left
💡 Hint
Check how the code handles spaces and punctuation.
✗ Incorrect
The code compares characters directly without skipping non-alphanumeric characters, so strings with spaces or punctuation may fail even if they are palindromes ignoring those characters.
🚀 Application
expertCount Palindromic Substrings Using Two Pointers
Given a string, which approach correctly counts all palindromic substrings using the two-pointer technique?
Attempts:
2 left
💡 Hint
Think about how palindromes can be centered at one or two characters.
✗ Incorrect
Counting palindromic substrings involves expanding around each possible center (single character or pair) using two pointers moving outward to check palindrome validity.
