Finding 3-Digit Even Numbers - Problem
You are given an integer array digits, where each element is a digit. The array may contain duplicates.
You need to find all the unique integers that follow the given requirements:
- The integer consists of the concatenation of three elements from digits in any arbitrary order.
- The integer does not have leading zeros.
- The integer is even.
For example, if the given digits were [1, 2, 3], integers 132 and 312 follow the requirements.
Return a sorted array of the unique integers.
Input & Output
Example 1 — Basic Case
$
Input:
digits = [2,1,3,0]
›
Output:
[102,120,130,132,210,230,310,312]
💡 Note:
All valid 3-digit even numbers using digits from [2,1,3,0]: First digit cannot be 0, last digit must be even (0 or 2). Numbers like 102, 120, 130, etc. are formed and sorted.
Example 2 — Limited Even Digits
$
Input:
digits = [2,7,4]
›
Output:
[274,472,724,742]
💡 Note:
Even digits available: 2, 4. Valid combinations: 274, 472, 724, 742. All start with non-zero and end with even digit.
Example 3 — No Valid Numbers
$
Input:
digits = [1,3,5]
›
Output:
[]
💡 Note:
All digits are odd, so no 3-digit even numbers can be formed. The last digit must be even.
Constraints
- 1 ≤ digits.length ≤ 100
- 0 ≤ digits[i] ≤ 9
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Given digits [2,1,3,0], identify constraints
2
Apply Rules
First digit ≠ 0, last digit must be even
3
Generate & Sort
Form all valid combinations and sort uniquely
Key Takeaway
🎯 Key Insight: A 3-digit number is valid if it doesn't start with 0 and ends with an even digit (0,2,4,6,8)
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code