Minimum Element After Replacement With Digit Sum
Real-world version: Smallest Folded Meter ReadingThe statement here is our own: the same inputs, outputs and technique.
A technician folds each meter reading before filing it. Folding a reading replaces it with the sum of its digits, so a reading of 4021 is filed as 4 + 0 + 2 + 1, which is 7.
readings holds the readings as they were taken. Every reading is folded once. Return the smallest of the filed values.
Examples
Example 1
- Input
- readings = [4021, 88, 705]
- Output
- 7
Folding gives 4 + 0 + 2 + 1 = 7 for the first reading, 8 + 8 = 16 for the second and 7 + 0 + 5 = 12 for the third. The smallest filed value is 7.
Example 2
- Input
- readings = [10, 9]
- Output
- 1
Folding gives 1 + 0 = 1 and 9. The smallest filed value is 1, taken from the larger of the two readings.
Example 3
- Input
- readings = [8888, 1000]
- Output
- 1
Folding gives 8 + 8 + 8 + 8 = 32 and 1 + 0 + 0 + 0 = 1.
Constraints
- 1 <= readings.length <= 100
- 1 <= readings[i] <= 10^4
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def smallest_after_folding(readings: list[int]) -> int:public int smallestAfterFolding(int[] readings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's