Bird
0
0
DSA Cprogramming~20 mins

Palindrome Detection in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Palindrome Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
APalindrome
BNot Palindrome
CCompilation Error
DRuntime Error
Attempts:
2 left
💡 Hint
Check if the string reads the same forwards and backwards.
Predict Output
intermediate
2: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;
}
APalindrome
BRuntime Error
CCompilation Error
DNot Palindrome
Attempts:
2 left
💡 Hint
Check if the first and last characters are the same.
🔧 Debug
advanced
2: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;
}
ACompilation Error
BPrints "Palindrome"
CRuntime Error (out-of-bounds access)
DPrints "Not Palindrome"
Attempts:
2 left
💡 Hint
Check how the right index is initialized.
🧠 Conceptual
advanced
1: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?
AO(n)
BO(n^2)
CO(log n)
DO(1)
Attempts:
2 left
💡 Hint
Consider how many character comparisons are made.
Predict Output
expert
3: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;
}
ANot Palindrome
BPalindrome
CCompilation Error
DRuntime Error
Attempts:
2 left
💡 Hint
Ignore spaces, commas, and case differences.