Problem · Array

Largest Number

Learn this problem
MediumLinkedIn logoLinkedInNEW GRADPHONE SCREEN

Problem statement

Given an array of nonnegative integers nums, arrange them so that their decimal representations form the largest possible number.

Return the result as a string. If every number is zero, return "0".

Function

largestNumber(nums: int[]) → String

Examples

Example 1

nums = [10,2]return = "210"

Placing 2 before 10 produces the larger concatenation.

Example 2

nums = [3,30,34,5,9]return = "9534330"

Ordering by pairwise concatenation places 9, 5, 34, 3, then 30.

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000000000

More LinkedIn problems

drafts saved locally
public String largestNumber(int[] nums) {
    // Write your code here
}
nums[10,2]
expected"210"
checking account