Skip to main content
Back to problems
#3270
Easy Algorithms

Find the key of the numbers

Math
76.5% acceptance
Feb 25, 2026
103
16
You are given three positive integers num1, num2, num3 (1 to 9999). Return the key: at each of the 4 digit positions (from most significant), take the minimum digit.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn generate_key(num1: i32, num2: i32, num3: i32) -> i32 {
    let mut result = 0;
    let mut mul = 1;
    let mut a = num1;
    let mut b = num2;
    let mut c = num3;
    for _ in 0..4 {
      let da = a % 10;
      let db = b % 10;
      let dc = c % 10;
      result += da.min(db).min(dc) * mul;
      mul *= 10;
      a /= 10;
      b /= 10;
      c /= 10;
    }
    result
  }
}