#949
Largest Time for Given Digits
expert · 1125 · lc medium +32 · verified · 35.9% accepted · 745 likes · top 14%
Description
Using each of the four digits in arr exactly once, form the latest valid 24-hour clock time in "HH:MM" format (hours 00–23, minutes 00–59). Return the time string, or "" if no valid arrangement exists.
Example 1:
Input: arr = [1,2,3,4]
Output: "23:41"
Explanation: The valid 24-hour times are "12:34", "12:43", "13:24", "13:42", "14:23", "14:32", "21:34", "21:43", "23:14", and "23:41". Of these times, "23:41" is the latest.
Example 2:
Input: arr = [5,5,5,5]
Output: ""
Explanation: There are no valid 24-hour times as "55:55" is not valid.
Code
1
2
3