Maximize the Canonical Concatenation of Integer Spellings

Quick Overview

Build the largest canonical decimal concatenation with a transitive pairwise string-order comparator.

Maximize the Canonical Concatenation of Integer Spellings

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Arrange all given nonnegative integers so that concatenating their ordinary decimal spellings forms the largest possible number. Return that number as a string, since it may exceed integer range. If all values are zero, represent the number as "0". ```cpp string largestNumber(vector<int>& nums); ``` ### Examples ```text Input: nums = [12,121,9] Output: "912121" ``` ```text Input: nums = [0,0,0] Output: "0" ``` ### Constraints - Length is between 1 and 100. - Each value is between 0 and 1000000000, inclusive. - Use every input occurrence; the result is the largest concatenated number, not a list of chosen indices.

Overview: Build the largest canonical decimal concatenation with a transitive pairwise string-order comparator.

Amazon logo
Amazon
Date not reported
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Arrange all given nonnegative integers so that concatenating their ordinary decimal spellings forms the largest possible number. Return that number as a string, since it may exceed integer range. If all values are zero, represent the number as "0".

string largestNumber(vector<int>& nums);

Examples

Input: nums = [12,121,9]
Output: "912121"
Input: nums = [0,0,0]
Output: "0"

Constraints

  • Length is between 1 and 100.
  • Each value is between 0 and 1000000000, inclusive.
  • Use every input occurrence; the result is the largest concatenated number, not a list of chosen indices.