Asked at

Largest Number

Medium
Verified
SortingGreedyString~25 min

Given non-negative integers nums, arrange them to form the largest possible number.

Compare two values by which concatenation order reads larger (a+b vs b+a), then join. Collapse all-zeros to "0". Return the result as a string.

The input arrives as a single array nums.

Examples

in[10, 2]
out"210"

2 before 10 gives 210, larger than 102.

in[3, 30, 34, 5, 9]
out"9534330"

Order by which concatenation reads larger.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 10⁹

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.