Skip to main content
Back to problems
#2094
Easy Algorithms

Finding 3 digit even numbers

Array Hash Table Recursion Sorting Enumeration
78.8% acceptance
Feb 25, 2026
1546
345
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. Return a sorted array of the unique integers.

Solution

Rust
Time O(n)
Space O(n)
LeetCode
solution.rs
impl Solution {
  pub fn find_even_numbers(digits: Vec<i32>) -> Vec<i32> {
    // Count frequency of each digit in input
    let mut freq = [0usize; 10];
    for &d in &digits {
      freq[d as usize] += 1;
    }

    let mut result = Vec::new();
    // Enumerate all 3-digit even numbers
    for num in (100..=998i32).step_by(2) {
      let d0 = (num / 100) as usize;   // hundreds
      let d1 = (num / 10 % 10) as usize; // tens
      let d2 = (num % 10) as usize;    // ones

      // Check if we can form this number from available digits
      let mut used = [0usize; 10];
      used[d0] += 1;
      used[d1] += 1;
      used[d2] += 1;

      if (0..10).all(|i| used[i] <= freq[i]) {
        result.push(num);
      }
    }
    result
  }
}