2094. Finding 3-Digit Even Numbers
UnknownView on LeetCode
Time: O(1000)
Space: O(1)
Problem Overview
Finding 3-Digit Even Numbers (Unknown) asks you to solve a structured algorithmic task. This is a common Array / Hash Table pattern in coding interviews. Count digit frequencies; enumerate all 3-digit even numbers and check feasibility with counts.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Approach
Count digit frequencies; enumerate all 3-digit even numbers and check feasibility with counts.
Related patterns: Array, Hash Table, Math
2094.cs
C#
// Approach: Count digit frequencies; enumerate all 3-digit even numbers and check feasibility with counts.
// Time: O(1000) Space: O(1)
public class Solution
{
public int[] FindEvenNumbers(int[] digits)
{
List<int> ans = new List<int>();
int[] count = new int[10];
foreach (var digit in digits)
++count[digit];
// Try to construct `abc`.
for (int a = 1; a <= 9; ++a)
{
for (int b = 0; b <= 9; ++b)
{
for (int c = 0; c <= 8; c += 2)
{
if (count[a] > 0 && count[b] > (b == a ? 1 : 0) &&
count[c] > (c == a ? 1 : 0) + (c == b ? 1 : 0))
ans.Add(a * 100 + b * 10 + c);
}
}
}
return ans.ToArray();
}
}Was this solution helpful?
Related Problems
- 822. Card Flipping Game(Unknown)
- 840. Magic Squares In Grid(Medium)
- 961. N-Repeated Element in Size 2N Array(Unknown)
- 1248. Count Number of Nice Subarrays(Medium)
- 1863. Sum of All Subset XOR Totals(Unknown)
- 1995. Count Special Quadruplets(Unknown)