↓Skip to main content
  1. LeetCode/

LeetCode 2094: Finding 3-Digit Even Numbers

·2 mins· ·
LeetCode Easy Hash-Table Enumeration Array
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2025-05-12

  • Submissions: Wrong Answer → Accepted

Approach
#

There are only 450 three-digit even numbers (100 to 998), so enumerating answers is simpler (Hash Table Template 1):

  • Count the digits available: have = Counter(digits).
  • For each candidate x, count the digits it needs: need = Counter(str(x)).
  • need - have keeps only “needed more than available”; empty means enough.

Enumerating in increasing order gives a sorted result with no duplicates.

My Attempts
#

I originally nested three loops over the counter keys to build the digits, excluding cases with too few copies. Attempt 1’s condition (j == k and counter[i] < 2) used the wrong variable; it should check counter[j]. For [3, 2, 2] the answer is [232, 322]; 322 ends in two 2s, and checking the count of 3 dropped it. Changing to counter[j] passed.

Solution
#

class Solution:
    def findEvenNumbers(self, digits: List[int]) -> List[int]:
        have = Counter(map(str, digits))
        return [x for x in range(100, 1000, 2) if not Counter(str(x)) - have]

Complexity
#

Time O(450 × 3 + n), i.e. O(n), space O(1) (at most 10 digits).

Mistakes to Avoid
#

  • With three nested loops, check the repeat count with the matching position’s variable.
  • Keep Counter key types consistent: strings on both sides.

Interview Explanation
#

There are only 450 three-digit even numbers, so I enumerate 100 to 998 by twos, count the digits each one needs, and compare with the digits on hand; an empty Counter difference means enough. Enumerating in order yields a sorted, duplicate-free result.

Related

LeetCode 3487: Maximum Unique Subarray Sum After Deletion
·2 mins
LeetCode Easy Greedy Hash-Table Array
LeetCode 3487 note: free deletion means picking distinct values; take every non-negative one, or only the maximum when all are negative
LeetCode 2099: Find Subsequence of Length K With the Largest Sum
·1 min
LeetCode Easy Array Hash-Table Sorting Heap-Priority-Queue
LeetCode 2099 note: pick the k largest values along with their indices, then sort by index to restore the original order
LeetCode 2357: Make Array Zero by Subtracting Equal Amounts
·1 min
LeetCode Easy Array Hash-Table Greedy Sorting
LeetCode 2357 note: each operation zeroes the group of the smallest positive value, so the answer is the number of distinct positive values
LeetCode 1122: Relative Sort Array
·1 min
LeetCode Easy Array Hash-Table Sorting Counting-Sort
LeetCode 1122 note: count first, emit values in arr2’s order, then append the remaining values in ascending order
LeetCode 1128: Number of Equivalent Domino Pairs
·2 mins
LeetCode Easy Array Hash-Table Counting
LeetCode 1128 note: normalize each domino to (small, large) as a key and count; a key with c dominoes yields c(c - 1) / 2 pairs
LeetCode 1002: Find Common Characters
·1 min
LeetCode Easy Array Hash-Table String
LeetCode 1002 note: count each word and intersect all Counters (minimum count per character), then expand