Find the Key of the Numbers - Problem
You are given three positive integers num1, num2, and num3.
The key of num1, num2, and num3 is defined as a four-digit number such that:
- Initially, if any number has less than four digits, it is padded with leading zeros.
- The ith digit (
1 <= i <= 4) of the key is generated by taking the smallest digit among the ith digits ofnum1,num2, andnum3.
Return the key of the three numbers without leading zeros (if any).
Input & Output
Example 1 — Basic Case
$
Input:
num1 = 1, num2 = 22, num3 = 333
›
Output:
21
💡 Note:
Pad to 4 digits: 0001, 0022, 0333. Position-wise minimums: 0,0,2,1 → Key = 0021 → 21
Example 2 — All Same Length
$
Input:
num1 = 1234, num2 = 5678, num3 = 9012
›
Output:
1012
💡 Note:
Already 4 digits. Position-wise minimums: min(1,5,9)=1, min(2,6,0)=0, min(3,7,1)=1, min(4,8,2)=2 → 1012
Example 3 — Leading Zeros Result
$
Input:
num1 = 987, num2 = 123, num3 = 456
›
Output:
123
💡 Note:
Pad to 4 digits: 0987, 0123, 0456. Position-wise minimums: 0,1,2,3 → Key = 0123 → 123
Constraints
- 1 ≤ num1, num2, num3 ≤ 9999
- All three numbers are positive integers
Visualization
Tap to expand
Understanding the Visualization
1
Input
Three positive integers of varying lengths
2
Process
Pad to 4 digits and find minimum at each position
3
Output
Key without leading zeros
Key Takeaway
🎯 Key Insight: Pad all numbers to same length, then compare digits position by position to build the key
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code