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 of num1, num2, and num3.

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
Find the Key: Input → Process → OutputStep 1: Inputnum1 = 1num2 = 22num3 = 333Step 2: ProcessPad to 4 digits:000100220333Find minimum per position:0021Step 3: OutputKey = "0021"Remove leading zerosResult: 21
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
Asked in
Google 15 Amazon 12
8.5K Views
Medium Frequency
~8 min Avg. Time
350 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen