Ctrl K

Latest Clock From Digits

Medium
Four digits digits fell off a digital clock display. Put them back as a 24-hour time "HH:MM", using every digit exactly once: hours from 00 to 23, minutes from 00 to 59. Return the latest time you can build. If no valid time is possible, return an empty string.
Example 1
digits=[0, 7, 1, 5] → '17:50'

Hour 17 is the latest possible one, leaving 0 and 5: "17:50".

Example 2
digits=[8, 8, 3, 9] → ''

Every hour built from these digits is above 23, so no time can be made.

Example 3
digits=[0, 0, 0, 0] → '00:00'
Constraints
  • len(digits) == 4
  • 0 ≤ digits[i] ≤ 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSwapped Initials Names HardLetter Counts of Shortest Covers HardAnagram Buckets MediumWord Traced on a Letter Grid MediumSplit Into Dictionary Words Medium
loading Python…
Input
digits=[0, 7, 1, 5]
Expected
'17:50'

Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.