String Modification
Submissions: 744   Accuracy:

44.95%

  Difficulty: Easy   Marks: 2

You have been given a string s as input and you have to print it's modified form.A string is modified in the following way:-

All the duplicates are removed from the original string and the modified string contains the characters in the order of their frequency .i.e, character with the higher frequency should come first than the character with the lower frequency in the modified string and if the two characters have the same frequency in the original string then it should occur in alphabetical order in the new modified string.

Input:

First line of input contains an integer T denoting the number of test cases.Each test case consist of a single line containing a string s to be modified.
Output:

Print the modified string in a new line.
Constraints:

  • 1<=T<=1000
  • length of each string<=100 and there is no space in between the strings.
  • Only lowercase characters are present in the string.

Example:

Input:

2
geeksforgeeks

helloworld

Output:

egksfor

lodehrw

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

Contributor: RIYA BHARDWAJ
Author: Riya Bhardwaj


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.