class Solution:
def largestTimeFromDigits(self, A: List[int]) -> str:
#time O(1) since length is 4 space O(1)
# main idea: use feature of time ==> hour <24 and minute <60 to filter out invalid time. then find max time by comparing time (converted to minutes)
max_minut = -1
res = ""
for i,j,k,l in itertools.permutations(A):
hour = i*10 + j
minut = k*10 + l
if hour < 24 and minut < 60:
max_minut = max(max_minut, hour*60+minut)
if max_minut == -1:
return res
else:
return "{:02d}:{:02d}".format(max_minut//60,max_minut%60)