Unique 3-Digit Even Numbers - Problem
Problem: You have a collection of digits, and you need to find how many distinct 3-digit even numbers you can form using them.
Rules:
• Each digit can only be used once per number
• No leading zeros allowed (numbers must be 100-999)
• The number must be even (last digit must be 0, 2, 4, 6, or 8)
Example: Given
Goal: Count all possible distinct 3-digit even numbers that can be formed.
Rules:
• Each digit can only be used once per number
• No leading zeros allowed (numbers must be 100-999)
• The number must be even (last digit must be 0, 2, 4, 6, or 8)
Example: Given
[2, 1, 3, 0], you can form: 102, 120, 130, 132, 210, 230, 302, 310, 312, 320 → 10 unique even numbersGoal: Count all possible distinct 3-digit even numbers that can be formed.
Input & Output
example_1.py — Basic Case
$
Input:
[2,1,3,0]
›
Output:
10
💡 Note:
Possible even numbers: 102, 120, 130, 132, 210, 230, 302, 310, 312, 320. All digits 1-9 can be first digit (no leading zeros), any digit can be middle, and only even digits (0,2) can be last.
example_2.py — Duplicate Digits
$
Input:
[2,2,8,8,2]
›
Output:
1
💡 Note:
With three 2s and two 8s, we can form: 228, 282, 822, 288, 828, 882. However, only 228, 282, 822, 288, 828, 882 are valid... Wait, let me recalculate: we need 3 different positions. Possible: 228, 282, 822, 288, 828, 882. Actually the answer should be 6, but with uniqueness constraint, it's still 6 unique numbers.
example_3.py — Edge Case with Zero
$
Input:
[0,2,0,0]
›
Output:
0
💡 Note:
No valid 3-digit even numbers can be formed because we only have 0 and 2, but we need a non-zero first digit. Since we only have one 2, we cannot form any valid 3-digit number.
Visualization
Tap to expand
Understanding the Visualization
1
Sort Your Stamps
Count how many of each digit (0-9) you have available
2
Choose First Digit
Pick from digits 1-9 only (no leading zeros allowed)
3
Choose Middle Digit
Pick from any remaining available digits (0-9)
4
Choose Last Digit
Pick from remaining even digits only (0,2,4,6,8)
5
Validate & Count
Ensure all chosen digits are available and add to result set
Key Takeaway
🎯 Key Insight: Instead of generating all permutations, we constrain our search by position requirements: first digit must be 1-9 (no leading zeros), last digit must be even (0,2,4,6,8), resulting in at most 9×10×5 = 450 combinations to check - a constant time solution!
Time & Space Complexity
Time Complexity
O(1)
At most 10×10×5 = 500 combinations to check (digits 0-9, with constraints)
✓ Linear Growth
Space Complexity
O(1)
Fixed size frequency array for digits 0-9, result set bounded by max possible numbers
✓ Linear Space
Constraints
- 1 ≤ digits.length ≤ 100
- 0 ≤ digits[i] ≤ 9
- Each element in digits represents a single digit
- No leading zeros allowed in 3-digit numbers
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code