Challenge - 5 Problems
Palindrome Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of palindrome check for a simple string
What is the output of this C code that checks if a string is a palindrome?
DSA C
#include <stdio.h> #include <string.h> int isPalindrome(char str[]) { int left = 0; int right = strlen(str) - 1; while (left < right) { if (str[left] != str[right]) { return 0; } left++; right--; } return 1; } int main() { char s[] = "radar"; if (isPalindrome(s)) { printf("Palindrome\n"); } else { printf("Not Palindrome\n"); } return 0; }
Attempts:
2 left
💡 Hint
Check if the string reads the same forwards and backwards.
✗ Incorrect
The string "radar" is the same when reversed, so the function returns 1 and prints "Palindrome".
❓ Predict Output
intermediate2:00remaining
Output for palindrome check with mixed characters
What will this C program print when checking the string "hello"?
DSA C
#include <stdio.h> #include <string.h> int isPalindrome(char str[]) { int left = 0; int right = strlen(str) - 1; while (left < right) { if (str[left] != str[right]) { return 0; } left++; right--; } return 1; } int main() { char s[] = "hello"; if (isPalindrome(s)) { printf("Palindrome\n"); } else { printf("Not Palindrome\n"); } return 0; }
Attempts:
2 left
💡 Hint
Check if the first and last characters are the same.
✗ Incorrect
The string "hello" is not the same forwards and backwards, so the function returns 0 and prints "Not Palindrome".
🔧 Debug
advanced2:00remaining
Identify the bug in palindrome detection code
What error does this code produce when checking the string "abba"?
DSA C
#include <stdio.h> #include <string.h> int isPalindrome(char str[]) { int left = 0; int right = strlen(str) - 1; while (left < right) { if (str[left] != str[right]) { return 0; } left++; right--; } return 1; } int main() { char s[] = "abba"; if (isPalindrome(s)) { printf("Palindrome\n"); } else { printf("Not Palindrome\n"); } return 0; }
Attempts:
2 left
💡 Hint
Check how the right index is initialized.
✗ Incorrect
The right index is set to strlen(str), which is one past the last character index, causing out-of-bounds access and runtime error.
🧠 Conceptual
advanced1:00remaining
Time complexity of palindrome detection
What is the time complexity of checking if a string of length n is a palindrome using the two-pointer approach?
Attempts:
2 left
💡 Hint
Consider how many character comparisons are made.
✗ Incorrect
The two-pointer approach compares characters from both ends moving inward, making at most n/2 comparisons, which is O(n).
❓ Predict Output
expert3:00remaining
Output of palindrome check ignoring case and non-alphanumeric characters
What is the output of this C program that checks if a string is a palindrome ignoring case and non-alphanumeric characters?
DSA C
#include <stdio.h> #include <ctype.h> #include <string.h> int isAlphaNum(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } int isPalindrome(char str[]) { int left = 0; int right = strlen(str) - 1; while (left < right) { while (left < right && !isAlphaNum(str[left])) left++; while (left < right && !isAlphaNum(str[right])) right--; if (tolower(str[left]) != tolower(str[right])) { return 0; } left++; right--; } return 1; } int main() { char s[] = "A man, a plan, a canal: Panama"; if (isPalindrome(s)) { printf("Palindrome\n"); } else { printf("Not Palindrome\n"); } return 0; }
Attempts:
2 left
💡 Hint
Ignore spaces, commas, and case differences.
✗ Incorrect
Ignoring non-alphanumeric characters and case, the string reads the same forwards and backwards, so it prints "Palindrome".
