Longest Palindromic Substring

Try to solve the Longest Palindromic Substring problem.

Statement#

Given a string s, return the longest palindromic substring in s.

Constraints

  • 11 \leq s.length 1000\leq 1000

  • s consist of only digits and English letters.

Examples#

Created with Fabric.js 3.6.6

1 of 2

Created with Fabric.js 3.6.6

2 of 2

Understand the problem#

Let’s take a moment to make sure you have correctly understood the problem. The quiz below helps you check that you are solving precisely the right problem:

Longest Palindromic Substring

1

Which of the following is the longest palindromic substring in “abcdefghgfe”

A)

“ghg”

B)

“abcdefghgfe”

C)

“efghgfe”

Question 1 of 20 attempted

Try it yourself#

Implement your solution in the following coding playground.

The optimal solution to this problem runs in O(n2) time and takes O(n2) space.

Python
usercode > main.py
Input #1
Longest Palindromic Substring

You might want to go over the Dynamic Programming pattern again.

Solution: Combination Sum

Solution: Longest Palindromic Substring