Largest Number

Medium Greedy AI round

nums is a list of whole numbers, none of them negative.

Put all of the numbers in a row, in any order you choose, and read their digits one after another as one number. For example, 7 and 45 make 745 or 457.

Return the largest number you can make this way, as a string, since it can be far too long for a number type. It starts with a 0 only when it is 0.

Example 1

Input: nums = [8,81,7]
Output: "8817"

8 goes before 81, since 881 is larger than 818, and 7 goes last: 8817.

Example 2

Input: nums = [0,0,0]
Output: "0"

Example 3

Input: nums = [40,4,404,3]
Output: "4404403"

Constraints

  • 1 ≤ nums.length ≤ 2 × 10⁴
  • 0 ≤ nums[i] ≤ 10⁹

More Greedy

  • Gas StationAI round · Medium
  • CandyAI round · Hard
  • Increasing Triplet SubsequenceMedium
  • Minimum Number of Arrows to Burst BalloonsMedium
  • Can Place FlowersEasy
All Greedy problems