Largest Number

MediumGreedycustom sort

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given a list of non-negative integers nums, arrange them in some order and concatenate their decimal representations to form the largest possible number. Because the result may be far too large for any integer type, return it as a string. The result must not have leading zeros: if every number is 0, return "0".

Examples

Input: nums = [10,2]
Output: "210"
"2" + "10" = "210" beats "10" + "2" = "102".
Input: nums = [3,30,34,5,9]
Output: "9534330"
Ordering the pieces as 9, 5, 34, 3, 30 gives the largest concatenation.
Input: nums = [0,0]
Output: "0"
Both orders give "00", which is written as "0".

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 10^9

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.