Find the Longest Palindromic Substring

Given a string ‘S’ composed of lowercase English letters, your task is to identify the longest palindromic substring within ‘S’.

If there are multiple longest palindromic substrings of the same length, return the rightmost one in the given string.

Example:

Input:
bbbab
Output:
bab
Explanation:

In the string “bbbab”, there are two longest palindromic substrings of equal length: “bbb” and “bab”. The rightmost one, “bab”, should be returned.

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 100

Where ‘N’ is the length of the string.

Note:
A substring is a contiguous sequence of characters within a string. A string is a palindrome if it reads the same forwards and backwards.
Note:
You do not need to print anything; this has been handled. Implement the function to return the desired result.
AnswerBot
4mo

Find the longest palindromic substring in a given string, returning the rightmost one if multiple exist.

  • Use dynamic programming to check if substrings are palindromes

  • Iterate through the string and exp...read more

Help your peers!
Select
Add answer anonymously...

TCS iON Software Developer interview questions & answers

A Software Developer was asked 3mo agoQ. What are loops in Python?
A Software Developer was asked 3mo agoQ. What is the process to find a substring within an array?
A Software Developer was asked 8mo agoQ. How do you reverse a sorted array?

Popular interview questions of Software Developer

A Software Developer was asked 3mo agoQ1. What are loops in Python?
A Software Developer was asked 3mo agoQ2. What is the process to find a substring within an array?
A Software Developer was asked 6mo agoQ3. Why should we hire you?
TCS iON Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits