#C8843. Largest Number Formation
Largest Number Formation
Largest Number Formation
Given an array of non-negative integers, arrange them such that they form the largest possible number when concatenated together. The resulting number should be returned as a string. If the array consists of numbers which lead to leading zeros (e.g., [0, 0]), output "0".
You need to process multiple test cases from standard input. For each test case, you are given a number n followed by n integers. Your task is to output the largest number for each test case on a new line.
The ordering is determined by comparing the concatenation of any two numbers in both possible orders. In other words, for two numbers x and y (considered as strings), you should compare \(x+y\) and \(y+x\) in \(\LaTeX\) format. Use a greedy and sorting based approach to solve this problem.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each test case consists of two lines:
- The first line contains an integer \(n\), the number of elements in the array.
- The second line contains \(n\) non-negative integers separated by spaces.
All input is read from standard input.
outputFormat
For each test case, output a single line containing the largest possible number (as described) that can be formed by concatenating the given integers. All output should be printed to standard output.
## sample5
3
10 2 9
4
3 30 34 5
5
1 20 23 4 8
2
0 0
3
100 1000 10000
9210
534330
8423201
0
100100010000
</p>