Trains the technique from
LeetCode 3300Minimum Element After Replacement With Digit SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
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
Folding gives 1 + 0 = 1 and 9. The smallest filed value is 1, taken from the larger of the two readings.
Example 3
Folding gives 8 + 8 + 8 + 8 = 32 and 1 + 0 + 0 + 0 = 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def smallest_after_folding(readings: list[int]) -> int:public int smallestAfterFolding(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.