#K73702. Largest Number Formation
Largest Number Formation
Largest Number Formation
You are given T test cases. For each test case, you are given N non‐negative integers. Your task is to arrange the numbers such that they form the largest possible number when concatenated. In other words, given two numbers (x) and (y), you should order them such that the concatenation (xy) is greater than (yx) (where (xy) denotes the string formed by appending (y) after (x)).
This problem requires implementing a custom comparator that uses the formula
[
\text{compare}(x,y): ; \text{if } (x+y) > (y+x) ; \text{then } x \text{ should come before } y ]
and constructing the final number by concatenating the sorted numbers. If the result has a leading zero (i.e. all numbers are zeros), output "0".
inputFormat
The input is read from standard input (stdin).
The first line contains a single integer T, the number of test cases.
For each test case, the first integer N indicates how many numbers are in the test case, followed by N non-negative integers separated by spaces.
outputFormat
For each test case, output the largest number that can be formed by concatenating the given numbers, in a new line, to standard output (stdout).## sample
3
3 10 2 9
5 3 30 34 5 9
2 0 0
9210
9534330
0
</p>