Close
Topic list
Longest Palindromic Substring
MEDIUM
35 mins
Strings
Dynamic Programming
Topics (Covered in this problem)
Problem solved
Skill meter
Strings
-
-
Dynamic Programming
-
-
Other topics
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Longest Palindromic Substring

Contributed by
Ratnesh
Medium
0/80
Avg time to solve 35 mins
Success Rate 78 %
Share

## Problem Statement

#### Example:

``````Input: ‘S’ =’badam’

‘ada’ is the longest palindromic substring, and it can be proved that it is the longest possible palindromic substring.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
6
6
aaabbb
``````
##### Sample Output 1 :
``````dccd
aaa
``````
##### Explanation Of Sample Input 1 :
``````For test case 1:

‘dccd’ is the longest palindromic substring, and it can be proved that it is the longest possible palindromic substring.
Hence we return ‘dccd’.

For test case 2:

‘S’ =’aaabbb’

‘aaa’ is the longest palindromic substring, and it can be proved that it is the longest possible palindromic substring.
Hence we return ‘dccd’.
‘Bbb’ is also a valid answer.
``````
##### Sample Input 2 :
``````2
5
hello
1
a
``````
##### Sample Output 2 :
``````ll
a
``````
Auto
Console