Largest Number
Module 14 · Sorting
Problem
Given a list of non-negative integers, arrange them (as strings) to form the largest possible number, returned as a string.
Examples
Example 1
Input
[10, 2]Output"210"Example 2
Input
[3, 30, 34, 5, 9]Output"9534330"Example 3
Input
[0, 0]Output"0"Explanation. no leading zeros in the result
Constraints
1 ≤ n ≤ 10⁴ · values in [0, 10⁹].
Attempt it first
The whole problem is designing the right comparator — sorting isn't in numeric or lexicographic order, but by a custom rule that answers "which arrangement of THESE TWO pieces is bigger?" Find the comparator before opening the hint; the sort itself is one line once you have it.