Largest Number

Given a list of non-negative integers, arrange them such that they form the largest possible number and return it as a string. Pattern focus: Sorting First. Compare numbers by the concatenated order that yields the larger combined string, not by numeric value alone.

Input Format

nums = list of non-negative integers

Output Format

string representation of the largest concatenated number

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^9

Examples

Example 1:

Input:

nums = [10,2]

Output:

210

Explanation:

Comparing '10' and '2' shows that '2' should come first.

Example 2:

Input:

nums = [3,30,34,5,9]

Output:

9534330

Explanation:

Sorting by pairwise concatenation produces the lexicographically largest number.

Example 3:

Input:

nums = [0,0]

Output:

0

Explanation:

Leading zeros must be collapsed to a single zero.

Loading...
Largest Number - Greedy DSA Problem