Skip to main content
Back to problems
Leetcode
Easy
Arrays
Math
Sets
Combinatorics
Unique 3 Digit Even Numbers

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.

Acceptance 100%
Problem Statement

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 digits containing decimal digits from 0 to 9.

Output Format

  • Return an integer: the count of distinct 3-digit even numbers that can be formed.

Constraints

  • 1 <= digits.length <= 10
  • 0 <= 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.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.