
Asked in Nagarro
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.
Iterate through the string and expand around each character to find palindromes
Keep track of the...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Nagarro
Q. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
Q. Explain Kafka and how you would implement it.
Q. Is the directory a file?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Nagarro Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

