
smallestUnusualNumber
Let’s call an integer unusual if the sum of its digits is larger than the product of its digits.
For example, the numbers 21
and 990
are unusual, while the numbers 22
and 991
aren’t.
Given an integer a
(represented as a string), find the smallest unusual integer x
such that x ≥ a
. Since both x
and a
can be very large, return the value of x - a
.
Example
- For
a = "42"
, the output should besmallestUnusualNumber(a) = 8
.
The smallest unusual number that is greater than or equal to42
is50
, and50 - 42 = 8
.
Input/Output
-
[execution time limit] 0.5 seconds
-
[input] string a
A string representing a positive integer without leading zeros.
Guaranteed constraints:
1 ≤ a.length ≤ 102
. -
[output] integer
- The difference between the smallest unusual number that is larger than or equal to
a
, anda
.
- The difference between the smallest unusual number that is larger than or equal to
Post Comment