`late_clock` function receive an array with 4 digits and should return the latest time that can be built with those digits.
The time should be in `HH:MM` format.

Examples:
```
[1, 9, 8, 3] => 19:38
[9, 1, 2, 5] => 21:59
```

You can suppose the input is correct and you can build from it a correct 24-hour time.

Difficulty: introductory

Starter code:

def late_clock(digits):
	

Solutions:
from itertools import permutations

def late_clock(digits):
  for p in permutations(sorted(digits, reverse=True)):
    if p[0] > 2 or (p[0] == 2 and p[1] > 3) or p[2] > 5: continue
    return '{}{}:{}{}'.format(*p)

def late_clock(digits):
    res, digits = [], digits[:]
    def rec(i):
        if i == 3:
            res.append(digits.pop())
            return True
        maxi = 2 if i==0 else 5 if i==2 else 3 if res[0]==2 else 9
        for x in range(maxi, -1, -1):
            if x in digits:
                res.append(digits.pop(digits.index(x)))
                if rec(i+1): return True
                digits.append(res.pop())
        return False
        
    rec(0)
    return "{}{}:{}{}".format(*res)

from itertools import permutations


def late_clock(digits):
    for combo in permutations(sorted(digits, reverse=True)):
        if combo[:2] < (2, 4) and combo[2] < 6:
            return "{}{}:{}{}".format(*combo)

from itertools import permutations

def late_clock(digits):
    return max(
        f'{a}{b}:{c}{d}'
        for a,b,c,d in permutations(digits)
        if 0 <= a*10+b < 24 and 0 <= c*10+d < 60
    )

def late_clock(digits):
    result = ''
    minute = '_'
    lessSix = 0
    digits = sorted(digits, reverse = True)
    for d in digits:
        if d < 6:
            lessSix += 1
    for d in digits:
        if d < 3:
            if lessSix < 3 and d == 2:
                continue
            result += str(d)
            digits.remove(d)
            break
    for d in digits:
        if (d < 4 and result == '2') or (d < 10 and result != '2'):
            result += str(d) + ':'
            digits.remove(d)
            break
    for d in digits:
        if d < 6:
            minute= str(d)
            digits.remove(d)
            break
    result += minute + str(digits.pop())
    return result

from itertools import permutations

def late_clock(digits):
    return "{}{}:{}{}".format(*max(c for c in permutations(digits) if c[:2] < (2,4) and c[2:] < (6,0)))

from itertools import permutations

def late_clock(digits):
    mx = max(t for t in [''.join(p) for p in permutations(''.join(str(d) for d in digits))] if t[:2] < '24' and t[2:] < '60')
    return '{}:{}'.format(mx[:2], mx[2:])

from itertools import permutations


def late_clock(digits):
    decreasing_combos = permutations(sorted(digits, reverse=True))
    max_combo = next(c for c in decreasing_combos if c[:2] < (2, 4) and c[2] < 6)
    return "{}{}:{}{}".format(*max_combo)

from itertools import *
from datetime import *

def late_clock(digits):
    dt = []
    for a,b,c,d in permutations(digits,4):
        try:
            dt.append(datetime.strptime(f'{a}{b}:{c}{d}', '%H:%M'))
        except:
            pass
    return max(dt).strftime('%H:%M')

from datetime import datetime as dt
from itertools import permutations
def late_clock(a):
    li = []
    for i in permutations(list(map(str, a))): 
        try : d = dt.strptime(f'{"".join(i[:2])}:{"".join(i[2:])}', "%H:%M")
        except : continue
        li.append(d)
    return str(min(li, key=lambda x: dt.now() - x))[11:16]