Want to solve this problem? Login now to get access to solve the problems
A substring is a contiguous segment of a string.
The first line of input contains a single integer T, representing the number of test cases or queries to be run. Then the T test cases follow. The first and only one of each test case contains a string (STR).
For every test case, print the longest palindromic substring. If there are multiple possible answers then you need to print the substring which has the lowest starting index.
Do not print anything. It has already been taken care of. Try to solve it using O(1) space complexity.
1 <= T <= 10 0 <= N <= 10^3 Time Limit: 1 sec
For string "abccbc" there are multiple palindromic substrings like a,b,c,cc,bccb,cbc. But bccb is of longest length. Thus, answer is bccb.
For string "aeiou" there are multiple palindromic substrings like a,e,i,o,u, and all of the same length. But "a" palindromic substring has the minimum starting index. Thus, answer is "a".