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
Finding 3-Digit Even Numbers: Input → Process → OutputInput Digits[2, 1, 3, 0]Constraints• First digit ≠ 0• Last digit must be even• 3 digits totalValid Numbers102, 120, 130, 132210, 230, 310, 312Algorithm Process1. Try all combinations2. Check constraints3. Sort unique resultsof 3 digitsper rulesand return arrayOutput: [102,120,130,132,210,230,310,312]
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)
Asked in
Amazon 25 Google 20 Microsoft 15
32.0K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen