Skip to main content

Valid 24-Hour Times from Digits

easy
Software engineer

Given four integers A, B, C, and D representing digits, determine the number of valid times that can be displayed on a 24-hour digital clock using each digit exactly once.

A valid time follows the format "HH:MM" where the range spans from 00:00 to 23:59 inclusive.

  • The first digit of the hour must be between 0 and 2.
  • If the first digit of the hour is 2, the second digit must be between 0 and 3.
  • The first digit of the minute must be between 0 and 5.
  • The second digit of the minute can be any of the remaining digits.

Example 1

Input

A = 1, B = 8, C = 3, D = 2

Output

6

Explanation

Using the digits {1, 8, 3, 2}, we can form the following valid 24-hour times: "12:38", "13:28", "18:23", "18:32", "21:38", and "23:18". Each digit is used exactly once per time string.

Example 2

Input

A = 2, B = 3, C = 3, D = 2

Output

3

Explanation

The valid times are "22:33", "23:23", and "23:32".

Example 3

Input

A = 6, B = 2, C = 4, D = 7

Output

0

Explanation

No combination of these digits can form a valid hour (00-23) and minute (00-59).

Constraints

  • 0 <= A, B, C, D <= 9

OA

ArrayEnumerationHash TableSimulation
Language
Code editor loads in the browser.

Output

Input

1
8
3
2

Expected

6

Your output

Run to see your output.