All problems
0835EasyArrayMath

Smallest Folded Meter Reading

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3300Minimum Element After Replacement With Digit Sum

This 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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def smallest_after_folding(readings: list[int]) -> int:
Java
public int smallestAfterFolding(int[] readings)
September 7
Apply