Problem statement

https://binarysearch.com/problems/Create-Largest-Number-From-a-List/

Solution

Equal to Leetcode 0179. Largest Number.

Complexity

It is O(n log n) for time and O(n) for space.

Code

class Solution:
    def solve(self, nums):
        strs = [str(x) for x in nums]
        compare = lambda a, b: -1 if a+b > b+a else 1 if a+b < b+a else 0
        return "".join(sorted(strs, key = cmp_to_key(compare)))