Write a function that arranges a list of non-negative integers to form the largest possible number.
Given an array of integers, rearrange them such that when concatenated, they produce the maximum possible numeric value.
Input
- An array
arr of non-negative integers.
Output
- A string representing the largest number that can be formed by arranging the given integers.
Constraints & Edge Cases
-
All integers in the array are non-negative.
-
The resulting number may be very large, so return it as a string.
-
If all numbers are 0, return "0" (not "000").
-
The array may contain duplicate numbers.
-
When comparing numbers for arrangement, treat them as strings:
//Example 1:
Input:
const arr = [3, 30, 34, 5, 9]
output: "9534330"
//Example 2:
Input:
const arr3 = [54, 546, 548, 60]
output: "6054854654"