Problem Β· Math
Come Looking for the Smallest Num Which Must Be > Than a Specific Num. π
Learn this problemProblem statement
To solve this problem, you gonna need to write up the func in the editor π
What you've been given: int Z
What your func is gonna do:
1. find the smallest num that is > than Z.
2. total of all the digits of the num you find must == 2 * (total of all digits of Z)
Memo π:
When solving this problem, you can mainly focus on correctness. As for your code performance, it would not be the focus this time π.
Function
gmsFindTheTinestGreaterThanANum(N: int) β intExamples
Example 1
N = 10return = 11As we can see, 11 is the smallest num that is > 10.
What is the total sum of all digits of 10? The ans is 1 + 0 = 1...
What is the total sum of all digits of 11? The ans is 1 + 1 = 2...
2 == 1 * 2, so 11 should be returned.
Example 2
N = 14return = 19The total of all the digits of 19 (1 + 9 = 10) == 2 * total of digits of 14 (1 + 4 = 5)
Example 3
N = 99return = 9999The sum of digits of 9999 (9 + 9 + 9 + 9 = 36) == total of digits of 99 (9 + 9 = 18).
Constraints
1 <= Z <= 500.