#K6216. Lexicographically Smallest String
Lexicographically Smallest String
Lexicographically Smallest String
You are given a string s
which can be rearranged by swapping any two characters an arbitrary number of times. Your task is to compute the lexicographically smallest string that can be obtained by these swaps. In other words, you must output the sorted version of the string.
The problem can also be extended to multiple test cases. The input begins with an integer T
, representing the number of test cases. Then, T
strings follow. For each string, output its lexicographically smallest (i.e., sorted) form on a new line.
Note: All outputs should be printed to standard output and inputs will be read from standard input.
inputFormat
The first line of input contains an integer T
representing the number of test cases. The following T
lines each contain a single string s
.
Input Format:
T s1 s2 ... sT
outputFormat
For each test case, output the lexicographically smallest string (i.e., the sorted order of characters) on a new line.
Output Format:
result1 result2 ... resultT## sample
3
dcba
hello
leetcode
abcd
ehllo
cdeeelot
</p>