0
0
DSA Pythonprogramming~10 mins

Longest Palindromic Substring in DSA Python - 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 longest palindrome substring as empty.

DSA Python
longest = [1]
Drag options to blanks, or click blank then click option'
A0
BNone
C""
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using None instead of an empty string.
Using a list or number instead of a string.
2fill in blank
medium

Complete 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'
Aleft - 1
Bright - 1
Cleft
Dleft + 1
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.
3fill in blank
hard

Fix 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'
As
Bcurrent
Clongest
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning longest to the whole string s.
Assigning longest to left index instead of substring.
4fill in blank
hard

Fill 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'
Ai
Bi + 1
Ci - 1
D0
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.
5fill in blank
hard

Fill 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'
Ai
Bi + 1
Ccurrent
Dlongest
Attempts:
3 left
💡 Hint
Common Mistakes
Using same index for left and right causing odd length palindrome only.
Not updating longest with current substring.