Quick Overview

Arrange nonnegative integers so their decimal strings form the largest possible concatenation. The prompt requires every value exactly once, returns a string for unbounded result length, defines the all-zero case, and includes order-sensitive examples.

Arrange Nonnegative Integers to Form the Largest Number

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

# Arrange Nonnegative Integers to Form the Largest Number Given a list of nonnegative integers, arrange all of them so that their decimal representations concatenate into the numerically largest possible value. Implement: ```text largestConcatenatedNumber(nums) -> string ``` Return a string because the result may exceed integer limits. If every input value is zero, return exactly `"0"`. Every input element must be used once. ## Constraints - `1 <= nums.length <= 100,000` - `0 <= nums[i] <= 10^9` ## Examples ### Example 1 ```text nums = [10, 2] output = "210" ``` ### Example 2 ```text nums = [3, 30, 34, 5, 9] output = "9534330" ```

Quick Answer: Arrange nonnegative integers so their decimal strings form the largest possible concatenation. The prompt requires every value exactly once, returns a string for unbounded result length, defines the all-zero case, and includes order-sensitive examples.

Given a list of nonnegative integers, arrange every value exactly once so that their decimal representations concatenate into the numerically largest possible value. Return the result as a string because it may exceed integer limits. If every input value is zero, return exactly "0".

Constraints

  • 1 <= nums.length <= 100,000
  • 0 <= nums[i] <= 10^9
  • Every input element must be used exactly once.

Examples

Input: ([10, 2],)

Expected Output: '210'

Explanation: Placing 2 before 10 produces the larger concatenation.

Input: ([3, 30, 34, 5, 9],)

Expected Output: '9534330'

Explanation: The source example needs concatenation order rather than ordinary numeric order.

Hints

  1. For two decimal strings a and b, compare a+b with b+a.
  2. Handle the all-zero input with the required canonical output.

Loading coding console...