A rental company's vehicles have a display fault: whenever an odometer would show its true mileage reading, every digit of the display is replaced by the single largest digit that appears anywhere in that true reading. For example, a true reading of 523 would be displayed as 555, since 5 is the largest digit in 523; a true reading of 8 would still be displayed as 8.
Given the true (GPS-logged) readings for every vehicle in the fleet, compute the sum of what the faulty odometers would display across the whole fleet.
Line 1: an integer n — the number of vehicles.
Line 2: n integers, space-separated — the true odometer readings.
A single integer: the sum of the faulty (digit-replaced) readings.
Example 1
Input
3 1 2 3
Expected
6
Explanation
Each reading is a single digit, so its own largest digit is itself and the faulty display matches the true reading exactly: 1, 2, 3. The sum is 1+2+3 = 6.
Example 2
Input
2 523 213
Expected
888
Explanation
For 523, the largest digit is 5, so the display shows 555. For 213, the largest digit is 3, so the display shows 333. The total is 555+333 = 888.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →