Skip to main content

Valid Time Combinations

easy
Software engineer

Given four integers A, B, C, and D representing four individual digits, determine the total number of unique valid times in a 24-hour format (HH:MM) that can be formed using each of the four digits exactly once.

A 24-hour time is valid if:

  • The hours HH are between 00 and 23 inclusive.
  • The minutes MM are between 00 and 59 inclusive.

Note that digits can be identical (e.g., if the input is 1, 1, 1, 1, only one unique time 11:11 can be formed).

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:
1. **12:38** (Hours 12 < 24, Minutes 38 < 60)
2. **13:28** (Hours 13 < 24, Minutes 28 < 60)
3. **18:23** (Hours 18 < 24, Minutes 23 < 60)
4. **18:32** (Hours 18 < 24, Minutes 32 < 60)
5. **21:38** (Hours 21 < 24, Minutes 38 < 60)
6. **23:18** (Hours 23 < 24, Minutes 18 < 60)
Any other permutation (like 81:23 or 12:83) is invalid because the hours or minutes exceed the allowed limits.

Example 2

Input

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

Output

3

Explanation

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

Example 3

Input

A = 0, B = 0, C = 0, D = 0

Output

1

Explanation

Only 00:00 is possible.

Constraints

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

OA

EnumerationHash TableString
Language
Code editor loads in the browser.

Output

Input

1
8
3
2

Expected

6

Your output

Run to see your output.