File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
30 Days September Challange/Week 1/1. Largest Time for Given Digits Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Given an array of 4 digits, return the largest 24 hour time that can be made.
3
+
4
+ The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight.
5
+
6
+ Return the answer as a string of length 5. If no valid time can be made, return an empty string.
7
+
8
+
9
+
10
+ Example 1:
11
+
12
+ Input: [1,2,3,4]
13
+ Output: "23:41"
14
+ Example 2:
15
+
16
+ Input: [5,5,5,5]
17
+ Output: ""
18
+ """
19
+
20
+
21
+ class Solution :
22
+ def largestTimeFromDigits (self , A : List [int ]) -> str :
23
+ temp = [t for t in itertools .permutations (A ) if t [:2 ] < (2 , 4 ) and t [2 :] < (6 , 0 )]
24
+ if temp :
25
+ result = max (temp )
26
+ else :
27
+ return ''
28
+ final = ''
29
+ for i , num in enumerate (result ):
30
+ if i == 2 :
31
+ final += ':'
32
+ final += str (num )
33
+ return final
You can’t perform that action at this time.
0 commit comments