Python solution using custom comparator


#1
def cmp(): # using a comparator function
    class K():
        def __init__(A, value_of_a): # we are using 'A' instead of 'self' for better understanding and simulating a comparator
            A.val = value_of_a
        
        def __lt__(A, B):
            a = str(A.val)
            b = str(B.val)
            if a+b > b+a: return True
            return False
    return K

def largestNumber(arr):
    arr = list(arr)
    arr.sort(key = cmp())
    s = ""
    for ele in arr:
        s += str(ele)
    if s[0]=='0': return 0
    return s