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...
Ola Cabs SDE-2 interview questions & answers
A SDE-2 was asked Q. For each element in an array, find the sum of the smallest element to its left a...read more
A SDE-2 was asked Q. Can you explain the different types of joins in SQL and how to calculate the ave...read more
A SDE-2 was asked Q. Job Sequencing Problem Statement You are provided with a N x 2 2-D array called ...read more
Popular interview questions of SDE-2
A SDE-2 was asked Q1. For each element in an array, find the sum of the smallest element to its left a...read more
A SDE-2 was asked Q2. Can you explain the different types of joins in SQL and how to calculate the ave...read more
A SDE-2 was asked Q3. Job Sequencing Problem Statement You are provided with a N x 2 2-D array called ...read more
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

