Archana and her tricky string
Submissions: 592   Accuracy:

12.11%

  Difficulty: Easy   Marks: 2

Archana is very fond of strings. She likes to solve many questions related to strings. She comes across a problem which she is unable to solve. Help her to solve. The problem is as follows:-

Given is a string of length L. Her task is to find the longest string from the given string with characters arranged in descending order of their ASCII code and in arithmetic progression. She wants the common difference should be as low as possible(at least 1) and the characters of the string to be of higher ASCII value.  

Input:
The first line of input contains an integer T denoting the number of test cases. Each test contains a string s of length L.

Output:
For each test case print the longest string.

Constraints:
1<= T <= 100
3<= L <=1000
A<=s[i]<=Z
The string contains minimum three different characters.

Example:
Input:
2
ABCPQR
ADGJPRT
Output:
RQP
JGDA

Explanation:
Case 1:
Two strings of maximum length are possible- “CBA” and “RPQ”. But he wants the string to be of higher ASCII value therefore, the output is “RPQ”.
Case 2:
The String of maximum length is “JGDA”.

** For More Input/Output Examples Use 'Expected Output' option **

Author: kartikeyagoswami20


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.