Ctrl K

Smallest-Digit Code

Easy
A combination lock builds a four-digit code out of three numbers first, second and third. First, each number is written with exactly four digits, padding it with zeros on the left if needed (75 becomes 0075, for example). Then, for each of the four positions, the code takes the smallest of the three digits found at that position. Return the resulting code as a plain integer, that is, without leading zeros.
Example 1
first=4821, second=5317, third=6902 → 4301

Position by position: min(4, 5, 6) = 4, min(8, 3, 9) = 3, min(2, 1, 0) = 0, min(1, 7, 2) = 1. The code is 4301.

Example 2
first=75, second=3000, third=468 → 0

Padded with zeros they read 0075, 3000 and 0468. The first two positions give 0, the third gives min(7, 0, 6) = 0, the fourth min(5, 0, 8) = 0. That is 0000, so the answer is 0.

Example 3
first=999, second=919, third=991 → 911
Constraints
  • 1 ≤ first, second, third ≤ 9999
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
first=4821, second=5317, third=6902
Expected
4301

Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.