Count how many distinct 3-digit even numbers can be formed from a set of digits, using each input digit no more times than it appears.
You are given an array of digits. Form all possible 3-digit even numbers using the digits from the array.
A valid number must:
- contain exactly 3 digits,
- not start with 0,
- be even,
- use each digit at most as many times as it appears in the input.
Return the number of distinct valid numbers that can be formed.
Input Format
- An integer array
digitscontaining decimal digits from0to9.
Output Format
- Return an integer: the count of distinct 3-digit even numbers that can be formed.
Constraints
1 <= digits.length <= 100 <= digits[i] <= 9- A digit may be used no more times than it appears in
digits. - Numbers must be 3 digits long, cannot have a leading zero, and must be even.
Example 1
Input
digits = [2,1,3,0]
Output
12
Explanation
The distinct valid 3-digit even numbers include 102, 120, 130, 132, 201 is odd, and so on. In total, there are 12 distinct numbers.
Example 2
Input
digits = [2,2,8,8,2]
Output
3
Explanation
The distinct valid numbers are 222, 228, and 282? No, 282 is even and valid, while 822 is also valid. The distinct results are 222, 228, 282, 822, 828, and 882 only if digits allow them. Since there are three 2s and two 8s, the valid distinct numbers are 222, 228, 282, 822, 828, 882, so the count is 6.
Show 1 more example
Example 3
Input
digits = [0,0,0]
Output
0
Explanation
Any 3-digit number would start with 0, so no valid number can be formed.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.