Another Matrix Game
Submissions: 152   Accuracy:


  Difficulty: Basic   Marks: 1

Given a string S which contains only small letters. The task is to make a square matrix from string S. Then perform the following operations.
1. In each column delete the characters which occur more than one.
2. Column-wise sort the remaining characters in order abcd....wxyz. But print them in order azbycxdw....  
For example, after operation 1 if the remaining characters in a column are cedjki then after sorting they become cdeijk , now when printed in the given order the output will be ckdjei .

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a string S as input.

For each test case, in a new line print the above operations result. If there is no character left in the  matrix after operation 1 then print "0".

1 <= T <= 300
1 <= S <= 1000



In 1st test case
Matrix will be
a d g k
b d h l
c e i  l
c f  j m
In 1st column 'c', in 2nd column 'd' and in 4th column 'l' has occurred more than once. So after deleting them and sorting the remaining characters the matrix become

   a - g  k
   b - h  -
   - e i   -
   - f  j  m

So after operation 2 we get 'ab' from 1st column, 'ef' from 2nd column, 'gjhi' from 3rd column and 'km' from 4th column. Appending all of them we get the output as  "abefgjhikm".
In 3rd test case  
Matrix will be
a b c
a b c
a b c
So the output will be 0.

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

Contributor: Arun Tyagi
Author: arun03

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, generate link and share the link here.

to report an issue on this page.