Problem · Array
Valid Times on a Digital Clock
Learn this problemProblem statement
You are given four decimal digits a, b, c, and d.
Arrange all four supplied digit occurrences into a 24-hour time HH:MM. A time is valid when 00 <= HH <= 23 and 00 <= MM <= 59. Leading zeroes are allowed.
Return the number of distinct valid times that can be formed. Each supplied digit occurrence must be used exactly once; equal arrangements caused by repeated digits count only once.
Function
solution(a: int, b: int, c: int, d: int) → intExamples
Example 1
a = 1b = 2c = 3d = 4return = 10The digits form ten distinct valid times: 12:34, 12:43, 13:24, 13:42, 14:23, 14:32, 21:34, 21:43, 23:14, and 23:41.
Example 2
a = 1b = 4c = 1d = 4return = 3The distinct valid times are 11:44, 14:14, and 14:41. Repeated permutations of the equal digits do not add another time.
Example 3
a = 8b = 6c = 7d = 5return = 0No arrangement can put a valid digit in the tens place of the hour while also forming valid minutes.
Constraints
0 <= a, b, c, d <= 9- Each parameter represents one decimal digit occurrence.