Show problems as
Classic problem #3300EasyArrayMath

Minimum Element After Replacement With Digit Sum

Real-world version: Smallest Folded Meter Reading
Tracked in this browser only
Read Minimum Element After Replacement With Digit Sum on LeetCode(opens in a new tab)

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

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