Find Distinct Palindromic Substrings
Given a string 'S', identify and print all distinct palindromic substrings within it. A palindrome reads the same forwards and backwards. For example, 'bccb' is a palindrome, whereas 'def' is not.
Input:
The first line of input contains an integer ‘T’, indicating the number of test cases. Each following test case contains a single string 'S'.
Output:
For each test case, output all distinct palindromic substrings of the provided string. These substrings must be sorted and space-separated. Print each test case result on a new line.
Example:
Input:
T = 1 S = "abac"
Output:
a aba b c
Constraints:
- 1 <= T <= 10
- 1 <= |S| <= 1000
- String S is composed of lowercase English letters only.
- Time limit: 1 sec

AnswerBot
4mo
Given a string, find and print all distinct palindromic substrings within it.
Iterate through all possible substrings of the input string
Check if each substring is a palindrome
Store distinct palindromi...read more
Help your peers!
Add answer anonymously...
Top SDE-2 Interview Questions Asked at Ola Cabs
Q. For each element in an array, find the sum of the smallest element to its left a...read more
Q. Can you explain the different types of joins in SQL and how to calculate the ave...read more
Q. Job Sequencing Problem Statement You are provided with a N x 2 2-D array called ...read more
Interview Questions Asked to SDE-2 at Other Companies
Top Skill-Based Questions for Ola Cabs SDE-2
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
Java 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

