Bird
0
0
DSA Cprogramming~10 mins

Longest Palindromic Substring in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the maximum length of palindrome found.

DSA C
int maxLength = [1];
Drag options to blanks, or click blank then click option'
A1
B-1
C0
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing maxLength to 0 which ignores single character palindromes.
Using NULL which is not an integer.
2fill in blank
medium

Complete the code to expand around the center and check palindrome boundaries.

DSA C
while (left >= 0 && right < n && s[left] == s[right]) {
    left--;
    right++;
}
int length = right - left - [1];
Drag options to blanks, or click blank then click option'
A1
B0
C2
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Not subtracting 1 causes length to be off by 1.
Subtracting 0 or 2 leads to incorrect palindrome length.
3fill in blank
hard

Fix the error in the code that updates the start index of the longest palindrome found.

DSA C
if (length > maxLength) {
    start = left + [1];
    maxLength = length;
}
Drag options to blanks, or click blank then click option'
A-1
B1
C0
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using left directly without adjustment.
Adding 0 or 2 which shifts start incorrectly.
4fill in blank
hard

Fill both blanks to correctly check for odd and even length palindromes around center i.

DSA C
int len1 = expandAroundCenter(s, [1], [2]);
int len2 = expandAroundCenter(s, i, i + 1);
Drag options to blanks, or click blank then click option'
Ai
Bi - 1
Ci + 1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indices for left and right in odd palindrome check.
Using i-1 or i+1 which is for even length palindrome.
5fill in blank
hard

Fill all three blanks to update start and maxLength after finding the longer palindrome length.

DSA C
int maxLen = (len1 > len2) ? len1 : len2;
if (maxLen > maxLength) {
    start = i - (maxLen - [1]) / [2];
    maxLength = maxLen;
    end = i + maxLen / [3];
}
Drag options to blanks, or click blank then click option'
A1
B2
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Incorrect division causing wrong start or end indices.
Using 0 or 3 which do not represent half.