Problem · Array
Enumerate Valid Clock Times
Learn this problemProblem statement
Given exactly four decimal digits in digits, enumerate every valid 24-hour time that can be formed by using each supplied occurrence exactly once.
A valid time has format HH:MM, where 00 <= HH <= 23 and 00 <= MM <= 59. Preserve leading zeroes, remove duplicate times caused by equal digits, and return the times in chronological order.
Function
enumerateValidTimes(digits: int[]) → String[]Examples
Example 1
digits = [1,2,3,4]return = ["12:34","12:43","13:24","13:42","14:23","14:32","21:34","21:43","23:14","23:41"]These are exactly the valid chronological arrangements; arrangements such as 31:24 are not valid 24-hour times.
Example 2
digits = [0,0,1,2]return = ["00:12","00:21","01:02","01:20","02:01","02:10","10:02","10:20","12:00","20:01","20:10","21:00"]The two zero occurrences are both used, and duplicate permutations produce only one copy of each time.
Example 3
digits = [5,5,5,5]return = []No arrangement has a valid hour.
Constraints
digits.length == 4.0 <= digits[i] <= 9.
More Microsoft problems
- Maximum Score with Prime JumpsOA · Seen Aug 2026
- Minimum Jump CostOA · Seen Aug 2026
- Minimum Fuel Cost Between CitiesOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026