Longest Palindromic Substring Problem Statement
You are provided with a string STR
of length N
. The goal is to identify the longest palindromic substring within this string. In cases where multiple palindromic substrings have maximum lengths, return the substring which begins at the smaller index.
Input:
The first line consists of an integer 'T', indicating the number of test cases.
Each test case contains one line, a string 'STR'.
Output:
For each test case, print the longest palindromic substring on a separate line.
If there is more than one, choose the one with the smallest start index.
Example:
Input:
T = 1
STR = "ababc"
Output:
"aba"
Explanation:
The longest palindromic substring of "ababc" is "aba". Although "bab" is also a palindrome of the same length (3), "aba" starts earlier.
Constraints:
1 <= T <= 10
0 <= N <= 10^3
- Each 'STR' is composed of lowercase English letters.
- Time Limit: 1 second

AnswerBot
4mo
Identify the longest palindromic substring in a given string.
Iterate through the string and expand around each character to find palindromes
Keep track of the longest palindrome found
Return the longest...read more
Help your peers!
Add answer anonymously...
Jupiter Money Software Developer interview questions & answers
A Software Developer was asked Q. Design a Chess game using object-oriented principles.
A Software Developer was asked Q. Shortest Path in a Binary Matrix Problem Statement Given a binary matrix of size...read more
A Software Developer was asked Q. Can you explain how you would design a URL shortener?
Popular interview questions of Software Developer
A Software Developer was asked Q1. Design a Chess game using object-oriented principles.
A Software Developer was asked Q2. Shortest Path in a Binary Matrix Problem Statement Given a binary matrix of size...read more
A Software Developer was asked Q3. Can you explain how you would design a URL shortener?
>
Jupiter Money Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

