Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the longest palindrome length to 1.
DSA Go
longest := [1]Attempts:
3 left
💡 Hint
Common Mistakes
Setting longest to 0 causes errors when checking substrings.
Using len(s) assumes the whole string is palindrome initially.
✗ Incorrect
The minimum length of a palindrome substring is 1 (a single character).
2fill in blank
mediumComplete the code to expand around the center indices left and right.
DSA Go
for left >= 0 && right < len(s) && s[left] == s[right] { left-- right++ } start := left + 1 end := right - 1 length := [1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using right - left without adjustment gives incorrect length.
Using end - start misses the inclusive nature of indices.
✗ Incorrect
The length of the palindrome is end - start + 1 because both start and end are inclusive indices.
3fill in blank
hardFix the error in the palindrome check condition inside the loop.
DSA Go
for i := 0; i < len(s); i++ { l, r := i, i+1 for l >= 0 && r < len(s) && s[l] [1] s[r] { l-- r++ } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes the loop to break immediately.
Using '<' or '>' is incorrect for character equality check.
✗ Incorrect
We expand while characters at l and r are equal to find palindromes.
4fill in blank
hardFill both blanks to update the longest palindrome substring start and length.
DSA Go
if length > longest { longest = length startIndex = [1] endIndex = [2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i instead of start or end causes incorrect substring tracking.
Assigning length to indices is a type mismatch.
✗ Incorrect
We update startIndex to start and endIndex to end to track the longest palindrome boundaries.
5fill in blank
hardFill all three blanks to return the longest palindromic substring from s.
DSA Go
return s[[1]:[2]+[3]]
Attempts:
3 left
💡 Hint
Common Mistakes
Not adding 1 to endIndex excludes the last character.
Using longest instead of indices causes slicing errors.
✗ Incorrect
Slice from startIndex to endIndex + 1 to include the last character of the palindrome.
