Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the longest palindrome substring as empty.
DSA Python
longest = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using None instead of an empty string.
Using a list or number instead of a string.
✗ Incorrect
We start with an empty string to store the longest palindrome found.
2fill in blank
mediumComplete the code to expand around the center and return the palindrome substring.
DSA Python
def expand_around_center(s, left, right): while left >= 0 and right < len(s) and s[left] == s[right]: left -= 1 right += 1 return s[[1]:right]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning s[left:right] which misses the first character.
Returning s[left-1:right] which is out of bounds.
✗ Incorrect
After the loop, left and right are one step beyond the palindrome bounds, so we return s[left+1:right].
3fill in blank
hardFix the error in the code to update the longest palindrome substring correctly.
DSA Python
if len(current) > len(longest): longest = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning longest to the whole string s.
Assigning longest to left index instead of substring.
✗ Incorrect
We update longest to the current palindrome substring if it is longer.
4fill in blank
hardFill both blanks to correctly find odd length palindromes by expanding around center i.
DSA Python
for i in range(len(s)): current = expand_around_center(s, [1], [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indices for left and right causing wrong palindrome detection.
Starting from 0 instead of current index i.
✗ Incorrect
For odd length palindromes, expand around the same center index i.
5fill in blank
hardFill all three blanks to find even length palindromes by expanding around centers i and i+1.
DSA Python
for i in range(len(s)): current = expand_around_center(s, [1], [2]) if len(current) > len(longest): longest = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using same index for left and right causing odd length palindrome only.
Not updating longest with current substring.
✗ Incorrect
For even length palindromes, expand around i and i+1, then update longest if current is longer.